Jump to content

[Solved]FOV multiplier


Noah_Beech

Recommended Posts

recently I've been optimizing my custom bows and now everything about them is good (Right size, you hold them correctly, no more floppy arrows) But For the final part I've ran into a problem. The regular bow uses an FOV multiplier in EntityplayerSP to give a little zoom when you hold down the right click. The code looks something like this.

 

public float getFOVMultiplier()
    {
        float f = 1.0F;

        if (this.capabilities.isFlying)
        {
            f *= 1.1F;
        }

        f *= (this.landMovementFactor * this.getSpeedModifier() / this.speedOnGround + 1.0F) / 2.0F;

        if (this.isUsingItem() && this.getItemInUse().itemID == Item.bow.itemID)
        {
            int i = this.getItemInUseDuration();
            float f1 = (float)i / 20.0F;

            if (f1 > 1.0F)
            {
                f1 = 1.0F;
            }
            else
            {
                f1 *= f1;
            }

            f *= 1.0F - f1 * 0.15F;
        }

        return f;
    }

 

This FOV multiplier cannot seem to be used without modifying the class (A dumb idea haha) And I've heard maybe that reflection can do this? However I don't think so because it returns a local variable :/. Any help would be appreciated, thanks in advance!

 

~Noah

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

recently I've been optimizing my custom bows and now everything about them is good (Right size, you hold them correctly, no more floppy arrows) But For the final part I've ran into a problem. The regular bow uses an FOV multiplier in EntityplayerSP to give a little zoom when you hold down the right click. The code looks something like this.

 

public float getFOVMultiplier()
    {
        float f = 1.0F;

        if (this.capabilities.isFlying)
        {
            f *= 1.1F;
        }

        f *= (this.landMovementFactor * this.getSpeedModifier() / this.speedOnGround + 1.0F) / 2.0F;

        if (this.isUsingItem() && this.getItemInUse().itemID == Item.bow.itemID)
        {
            int i = this.getItemInUseDuration();
            float f1 = (float)i / 20.0F;

            if (f1 > 1.0F)
            {
                f1 = 1.0F;
            }
            else
            {
                f1 *= f1;
            }

            f *= 1.0F - f1 * 0.15F;
        }

        return f;
    }

 

This FOV multiplier cannot seem to be used without modifying the class (A dumb idea haha) And I've heard maybe that reflection can do this? However I don't think so because it returns a local variable :/. Any help would be appreciated, thanks in advance!

 

~Noah

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Okay, after looking at it for awhile, there is a variable in EntityRenderer called || private float fovMultiplierTemp; || And it obtains the value that is returned in getFOVMultiplier in this bit of code.

 

if (mc.renderViewEntity instanceof EntityPlayerSP)
        {
            EntityPlayerSP entityplayersp = (EntityPlayerSP)this.mc.renderViewEntity;
            this.fovMultiplierTemp = entityplayersp.getFOVMultiplier();
        }
        else
        {
            this.fovMultiplierTemp = mc.thePlayer.getFOVMultiplier();
        }

(Lines 345-370 in EntityRenderer)

 

This value is private, so would it be possible via reflection to make this variable change around (Possibly every tick, BTW)? It would be nice if there was a way to do this without reflection, as the value will constantly be changing (Possible lag?) 

 

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Okay, after looking at it for awhile, there is a variable in EntityRenderer called || private float fovMultiplierTemp; || And it obtains the value that is returned in getFOVMultiplier in this bit of code.

 

if (mc.renderViewEntity instanceof EntityPlayerSP)
        {
            EntityPlayerSP entityplayersp = (EntityPlayerSP)this.mc.renderViewEntity;
            this.fovMultiplierTemp = entityplayersp.getFOVMultiplier();
        }
        else
        {
            this.fovMultiplierTemp = mc.thePlayer.getFOVMultiplier();
        }

(Lines 345-370 in EntityRenderer)

 

This value is private, so would it be possible via reflection to make this variable change around (Possibly every tick, BTW)? It would be nice if there was a way to do this without reflection, as the value will constantly be changing (Possible lag?) 

 

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

recently I've been optimizing my custom bows and now everything about them is good (Right size, you hold them correctly, no more floppy arrows) But For the final part I've ran into a problem. The regular bow uses an FOV multiplier in EntityplayerSP to give a little zoom when you hold down the right click. The code looks something like this.

 

public float getFOVMultiplier()
    {
        float f = 1.0F;

        if (this.capabilities.isFlying)
        {
            f *= 1.1F;
        }

        f *= (this.landMovementFactor * this.getSpeedModifier() / this.speedOnGround + 1.0F) / 2.0F;

        if (this.isUsingItem() && this.getItemInUse().itemID == Item.bow.itemID)
        {
            int i = this.getItemInUseDuration();
            float f1 = (float)i / 20.0F;

            if (f1 > 1.0F)
            {
                f1 = 1.0F;
            }
            else
            {
                f1 *= f1;
            }

            f *= 1.0F - f1 * 0.15F;
        }

        return f;
    }

 

This FOV multiplier cannot seem to be used without modifying the class (A dumb idea haha) And I've heard maybe that reflection can do this? However I don't think so because it returns a local variable :/. Any help would be appreciated, thanks in advance!

 

~Noah

 

I did it as following:

1. In your bow, override the onUsingItemTick method

2. Create a method in your CommonProxy class, which can hold the ItemStack, the Player and the count parameter from the above overridden method as its own parameters (here I call it onBowFOVZoom):

onBowFOVZoom(ItemStack stack, EntityPlayer player, int count)

3. call the proxy method created before in your onUsingItemTick method, like this:

MyMod.proxy.onBowFOVZoom(stack, player, count);

4. Leave the method onBowFOVZoom in your CommonProxy blank, go to the ClientProxy and override that method there, here will be the neccessary code

5. copy the code inside the getFOVMultiplier() method (except the return statement) and paste it in the ClientProxy FOV method. Replace every "this" with the player parameter. WARNING: You need Reflection to access the speedOnGround variable. Here I suggest you use the ObfuscationReflectionHelper class. To access the field, do this:

float speedOnGround = ObfuscationReflectionHelper.getPrivateValue(EntityPlayer.class, player, "speedOnGround", "field_71108_cd");

The parameters are as following: Class to access - instance to access - decompiled variable name (for usage inside MCP) - "SRG-name" (for usage outside MCP, as an actual mod).

float f1 = (float)i / 20.0F;

This line determines how many ticks the bow needs to be fully charged. If your bow needs only 10 ticks, change the last float to 10F, if it needs 40, then to 40F. get it?

6. Go into the EntityRenderer class and find the method called "updateFovModifierHand()". Copy its code below the code you've already copied inside your ClientProxy method. But don't copy the first if-else statement, you don't need that. The block you would need is this one:

this.fovModifierHand += (this.fovMultiplierTemp - this.fovModifierHand) * 0.5F;

        if (this.fovModifierHand > 1.5F)
        {
            this.fovModifierHand = 1.5F;
        }

        if (this.fovModifierHand < 0.1F)
        {
            this.fovModifierHand = 0.1F;
        }

this.fovModifierHand and this.fovMultiplierTemp are private in EntityRenderer. this.fovMultiplierTemp is just the float variable f inside your method, so replace this.fovMultiplierTemp with f.

Now you need some more Reflection. Get the current fovModifierHand from the EntityRenderer instance you get with Minecraft.getMinecraft().entityRenderer _before_ the block this.fovModifierHand += (this.fovMultiplierTemp - this.fovModifierHand) * 0.5F; like this:

float fovModifierHand = ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");

You see how I used the ObfuscationReflectionHelper class again?

After doing that, you can remove every "this." in front of every fovModifierHand reference.

7. Now the final step: set the calculated FOV to the actual fovModifierHand variable inside Minecrafts EntityRenderer instance. To do this, use the ObfuscationReflectionHelper class again, but instead of getting a private value, you set one:

ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");

 

 

Note that this is really hacky and somehow "ugly", since the code is called every tick, but it works quite well and it doesn't impact the performance (I didn't noticed any difference, you have to test it out for yourself though). Also you have to keep track of variable name changes when you use the ObfuscationReflectionHelper, since inside the MCP environment, those name changes. The SRG-names are very unlikely to change, so you don't have to keep track on them as much as for the deobf-names. But nevertheless, you should test your stuff first before you publish your mod, not that the users get crashes :P

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

recently I've been optimizing my custom bows and now everything about them is good (Right size, you hold them correctly, no more floppy arrows) But For the final part I've ran into a problem. The regular bow uses an FOV multiplier in EntityplayerSP to give a little zoom when you hold down the right click. The code looks something like this.

 

public float getFOVMultiplier()
    {
        float f = 1.0F;

        if (this.capabilities.isFlying)
        {
            f *= 1.1F;
        }

        f *= (this.landMovementFactor * this.getSpeedModifier() / this.speedOnGround + 1.0F) / 2.0F;

        if (this.isUsingItem() && this.getItemInUse().itemID == Item.bow.itemID)
        {
            int i = this.getItemInUseDuration();
            float f1 = (float)i / 20.0F;

            if (f1 > 1.0F)
            {
                f1 = 1.0F;
            }
            else
            {
                f1 *= f1;
            }

            f *= 1.0F - f1 * 0.15F;
        }

        return f;
    }

 

This FOV multiplier cannot seem to be used without modifying the class (A dumb idea haha) And I've heard maybe that reflection can do this? However I don't think so because it returns a local variable :/. Any help would be appreciated, thanks in advance!

 

~Noah

 

I did it as following:

1. In your bow, override the onUsingItemTick method

2. Create a method in your CommonProxy class, which can hold the ItemStack, the Player and the count parameter from the above overridden method as its own parameters (here I call it onBowFOVZoom):

onBowFOVZoom(ItemStack stack, EntityPlayer player, int count)

3. call the proxy method created before in your onUsingItemTick method, like this:

MyMod.proxy.onBowFOVZoom(stack, player, count);

4. Leave the method onBowFOVZoom in your CommonProxy blank, go to the ClientProxy and override that method there, here will be the neccessary code

5. copy the code inside the getFOVMultiplier() method (except the return statement) and paste it in the ClientProxy FOV method. Replace every "this" with the player parameter. WARNING: You need Reflection to access the speedOnGround variable. Here I suggest you use the ObfuscationReflectionHelper class. To access the field, do this:

float speedOnGround = ObfuscationReflectionHelper.getPrivateValue(EntityPlayer.class, player, "speedOnGround", "field_71108_cd");

The parameters are as following: Class to access - instance to access - decompiled variable name (for usage inside MCP) - "SRG-name" (for usage outside MCP, as an actual mod).

float f1 = (float)i / 20.0F;

This line determines how many ticks the bow needs to be fully charged. If your bow needs only 10 ticks, change the last float to 10F, if it needs 40, then to 40F. get it?

6. Go into the EntityRenderer class and find the method called "updateFovModifierHand()". Copy its code below the code you've already copied inside your ClientProxy method. But don't copy the first if-else statement, you don't need that. The block you would need is this one:

this.fovModifierHand += (this.fovMultiplierTemp - this.fovModifierHand) * 0.5F;

        if (this.fovModifierHand > 1.5F)
        {
            this.fovModifierHand = 1.5F;
        }

        if (this.fovModifierHand < 0.1F)
        {
            this.fovModifierHand = 0.1F;
        }

this.fovModifierHand and this.fovMultiplierTemp are private in EntityRenderer. this.fovMultiplierTemp is just the float variable f inside your method, so replace this.fovMultiplierTemp with f.

Now you need some more Reflection. Get the current fovModifierHand from the EntityRenderer instance you get with Minecraft.getMinecraft().entityRenderer _before_ the block this.fovModifierHand += (this.fovMultiplierTemp - this.fovModifierHand) * 0.5F; like this:

float fovModifierHand = ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");

You see how I used the ObfuscationReflectionHelper class again?

After doing that, you can remove every "this." in front of every fovModifierHand reference.

7. Now the final step: set the calculated FOV to the actual fovModifierHand variable inside Minecrafts EntityRenderer instance. To do this, use the ObfuscationReflectionHelper class again, but instead of getting a private value, you set one:

ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");

 

 

Note that this is really hacky and somehow "ugly", since the code is called every tick, but it works quite well and it doesn't impact the performance (I didn't noticed any difference, you have to test it out for yourself though). Also you have to keep track of variable name changes when you use the ObfuscationReflectionHelper, since inside the MCP environment, those name changes. The SRG-names are very unlikely to change, so you don't have to keep track on them as much as for the deobf-names. But nevertheless, you should test your stuff first before you publish your mod, not that the users get crashes :P

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Thanks! But why do I need the ongroundspeed variable? lol I only want the FOV for the bows, or is there something I'm missing? Is that variable needed for something else?

 

~Noah

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Thanks! But why do I need the ongroundspeed variable? lol I only want the FOV for the bows, or is there something I'm missing? Is that variable needed for something else?

 

~Noah

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Thanks! But why do I need the ongroundspeed variable? lol I only want the FOV for the bows, or is there something I'm missing? Is that variable needed for something else?

 

~Noah

 

hm, now that you say it... I don't know xD

It has the value 0.1F in the EntityPlayer class and I don't see any modification to that value, so I guess you can use the actual value :P

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Thanks! But why do I need the ongroundspeed variable? lol I only want the FOV for the bows, or is there something I'm missing? Is that variable needed for something else?

 

~Noah

 

hm, now that you say it... I don't know xD

It has the value 0.1F in the EntityPlayer class and I don't see any modification to that value, so I guess you can use the actual value :P

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Is it normal for the zoom to start jiggling around when you reach the most amount of zoom? :P

 

It's because the zoom tries to reset every time. I have to improve this stuff (or wait for a hack, or make one myself and do a PR to Forge)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Is it normal for the zoom to start jiggling around when you reach the most amount of zoom? :P

 

It's because the zoom tries to reset every time. I have to improve this stuff (or wait for a hack, or make one myself and do a PR to Forge)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Yeah that is what I concluded too, Right now Im trying to make some sort of logic that fixes that but a PR would be nice, doing all of this just for a little FOV zoom is ridiculous... Last night I was going to make a PR but I was afraid Id screw something up and look like an ass :P

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Yeah that is what I concluded too, Right now Im trying to make some sort of logic that fixes that but a PR would be nice, doing all of this just for a little FOV zoom is ridiculous... Last night I was going to make a PR but I was afraid Id screw something up and look like an ass :P

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Okay, so I tried to do make it so the variable wouldn't attempt to change once you reach the max amount of zoom, with no luck, this is what I did...

 

if(72000-count <= 16)
    	{
        int i = player.getItemInUseDuration();
        float f1 = (float)i / 16.0F;

        if (f1 > 1.0F)
        {
            f1 = 1.0F;
            
        }
        else
        {
            f1 *= f1;
        }
    	
        f *= 1.0F - f1 * 0.15F;
    	}
    	else if(72000-count > 16){
    		
    		f= 0.85F;
    		
    	}
    }

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Okay, so I tried to do make it so the variable wouldn't attempt to change once you reach the max amount of zoom, with no luck, this is what I did...

 

if(72000-count <= 16)
    	{
        int i = player.getItemInUseDuration();
        float f1 = (float)i / 16.0F;

        if (f1 > 1.0F)
        {
            f1 = 1.0F;
            
        }
        else
        {
            f1 *= f1;
        }
    	
        f *= 1.0F - f1 * 0.15F;
    	}
    	else if(72000-count > 16){
    		
    		f= 0.85F;
    		
    	}
    }

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Okay, so I tried to do make it so the variable wouldn't attempt to change once you reach the max amount of zoom, with no luck, this is what I did...

 

if(72000-count <= 16)
    	{
        int i = player.getItemInUseDuration();
        float f1 = (float)i / 16.0F;

        if (f1 > 1.0F)
        {
            f1 = 1.0F;
            
        }
        else
        {
            f1 *= f1;
        }
    	
        f *= 1.0F - f1 * 0.15F;
    	}
    	else if(72000-count > 16){
    		
    		f= 0.85F;
    		
    	}
    }

 

I now made it with a tick handler. It works like a charm. You know the code you did in your bow? You don't need that. Create a client-side tick handler with TickType RENDER, then go to the tickStart method, check if it's TickType.RENDER, the player is using an item and if the used item ID equals with your bow. If yes, execute the method from the proxy.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Okay, so I tried to do make it so the variable wouldn't attempt to change once you reach the max amount of zoom, with no luck, this is what I did...

 

if(72000-count <= 16)
    	{
        int i = player.getItemInUseDuration();
        float f1 = (float)i / 16.0F;

        if (f1 > 1.0F)
        {
            f1 = 1.0F;
            
        }
        else
        {
            f1 *= f1;
        }
    	
        f *= 1.0F - f1 * 0.15F;
    	}
    	else if(72000-count > 16){
    		
    		f= 0.85F;
    		
    	}
    }

 

I now made it with a tick handler. It works like a charm. You know the code you did in your bow? You don't need that. Create a client-side tick handler with TickType RENDER, then go to the tickStart method, check if it's TickType.RENDER, the player is using an item and if the used item ID equals with your bow. If yes, execute the method from the proxy.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Okay, could you please at least give me a few pointers to what Im doing wrong? I've been trying the past 2 hours to get this to work but no luck so far :/.

 

Tickhandler

package mod_Rareores;

import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ClientTickHandler implements ITickHandler {


private void onPlayerTick(EntityPlayer player) {
if (player.isUsingItem() && player.getItemInUse().itemID == mod_rareores.ItemPherithiumBow.itemID){
	System.out.println("This works 10");
	mod_rareores.proxy.onBowFOVZoom(player);
}
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if(type.equals(EnumSet.of(TickType.RENDER))){
		System.out.println("This works 1");
		this.onPlayerTick((EntityPlayer)tickData[0]);


}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return null;
}

}

 

Commonproxy

package rareores.Common;

import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;
import mod_Rareores.ClientTickHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class CommonProxyRareores {

public void registerRenderers(){


}
public void onBowFOVZoom(EntityPlayer player){


}
public void registerClientTickHandler()
 {
  TickRegistry.registerTickHandler(new ClientTickHandler(), Side.CLIENT);
 }
}

 

Main File

//Declaring init
@Init
public void load(FMLInitializationEvent event){
	proxy.registerClientTickHandler();

 

But thanks for all the help, I'm really close to getting this done and I'm pretty excited :D (But a tiny bit stressed)

 

EDIT:

 

I change my tickhandler to this

package mod_Rareores;

import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ClientTickHandler implements ITickHandler {


private void onPlayerTick(EntityPlayer player) {

if (player.isUsingItem() && player.getItemInUse().itemID == mod_rareores.ItemPherithiumBow.itemID){
	System.out.println("This works 10");
	mod_rareores.proxy.onBowFOVZoom(player);
}
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if(type.equals(EnumSet.of(TickType.RENDER))){
		System.out.println("This works 1");
		this.onPlayerTick((EntityPlayer)tickData[0]);


}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks() {
	// TODO Auto-generated method stub
	 return EnumSet.of(TickType.RENDER, TickType.CLIENT);
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return null;
}

}

 

And got this crash

java.lang.ClassCastException: java.lang.Float cannot be cast to net.minecraft.entity.player.EntityPlayer
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at mod_Rareores.ClientTickHandler.tickStart(ClientTickHandler.java:24)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at cpw.mods.fml.common.SingleIntervalHandler.tickStart(SingleIntervalHandler.java:28)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at cpw.mods.fml.common.FMLCommonHandler.tickStart(FMLCommonHandler.java:121)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at cpw.mods.fml.common.FMLCommonHandler.onRenderTickStart(FMLCommonHandler.java:374)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:865)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:756)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at java.lang.Thread.run(Unknown Source)

At least I know my code is being ran >.>

 

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

Okay, could you please at least give me a few pointers to what Im doing wrong? I've been trying the past 2 hours to get this to work but no luck so far :/.

 

Tickhandler

package mod_Rareores;

import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ClientTickHandler implements ITickHandler {


private void onPlayerTick(EntityPlayer player) {
if (player.isUsingItem() && player.getItemInUse().itemID == mod_rareores.ItemPherithiumBow.itemID){
	System.out.println("This works 10");
	mod_rareores.proxy.onBowFOVZoom(player);
}
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if(type.equals(EnumSet.of(TickType.RENDER))){
		System.out.println("This works 1");
		this.onPlayerTick((EntityPlayer)tickData[0]);


}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return null;
}

}

 

Commonproxy

package rareores.Common;

import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;
import mod_Rareores.ClientTickHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class CommonProxyRareores {

public void registerRenderers(){


}
public void onBowFOVZoom(EntityPlayer player){


}
public void registerClientTickHandler()
 {
  TickRegistry.registerTickHandler(new ClientTickHandler(), Side.CLIENT);
 }
}

 

Main File

//Declaring init
@Init
public void load(FMLInitializationEvent event){
	proxy.registerClientTickHandler();

 

But thanks for all the help, I'm really close to getting this done and I'm pretty excited :D (But a tiny bit stressed)

 

EDIT:

 

I change my tickhandler to this

package mod_Rareores;

import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ClientTickHandler implements ITickHandler {


private void onPlayerTick(EntityPlayer player) {

if (player.isUsingItem() && player.getItemInUse().itemID == mod_rareores.ItemPherithiumBow.itemID){
	System.out.println("This works 10");
	mod_rareores.proxy.onBowFOVZoom(player);
}
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if(type.equals(EnumSet.of(TickType.RENDER))){
		System.out.println("This works 1");
		this.onPlayerTick((EntityPlayer)tickData[0]);


}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks() {
	// TODO Auto-generated method stub
	 return EnumSet.of(TickType.RENDER, TickType.CLIENT);
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return null;
}

}

 

And got this crash

java.lang.ClassCastException: java.lang.Float cannot be cast to net.minecraft.entity.player.EntityPlayer
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at mod_Rareores.ClientTickHandler.tickStart(ClientTickHandler.java:24)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at cpw.mods.fml.common.SingleIntervalHandler.tickStart(SingleIntervalHandler.java:28)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at cpw.mods.fml.common.FMLCommonHandler.tickStart(FMLCommonHandler.java:121)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at cpw.mods.fml.common.FMLCommonHandler.onRenderTickStart(FMLCommonHandler.java:374)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:865)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:756)
2013-04-21 12:27:04 [iNFO] [sTDERR] 	at java.lang.Thread.run(Unknown Source)

At least I know my code is being ran >.>

 

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

replace this:

(EntityPlayer)tickData[0]

with this:

Minecraft.getMinecraft().thePlayer

 

tickData[0] is the partialTickTime, which is a float.

 

Also you should check if Minecraft.getMinecraft().thePlayer is not null before executing your code.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.