Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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

Posted

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

Posted

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.

Posted

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.

Posted

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

Posted

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

Posted

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.

Posted

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.

Posted

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

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

Posted

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

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

Posted

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.

Posted

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.

Posted

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

Posted

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

Posted

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

Posted

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

Posted

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.

Posted

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.

Posted

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

Posted

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

Posted

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.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
    • When i join minecraft all ok, when i join world all working fine, but when i open indentity menu, i get this The game crashed whilst unexpected error Error: java.lang.NullPointerException: Cannot invoke "top.ribs.scguns.common.Gun$Projectile.getDamage()" because "this.projectile" is null crash report here https://paste.ee/p/0vKaf
  • Topics

×
×
  • Create New...

Important Information

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