Posted November 6, 201311 yr For some reason when I eat my custom food, my overwritten onEaten and onFoodEaten methods get called twice, so my stack size is reduced by 2 instead of 1. Here is my custom food class. Notice that I DO check for !par2World.isRemote and my food has a custom potion effect set in the constructor that acts like getting poison from raw chicken except the probability of getting the effect is %100: package eclipse.MoreApples.food; import cpw.mods.fml.common.network.Player; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import eclipse.MoreApples.potion.FlyingPotion; import eclipse.MoreApples.potion.FlyingPotionEffect; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.stats.StatList; import net.minecraft.util.DamageSource; import net.minecraft.world.World; public class FoodAppleFlight extends ItemFood{ static boolean hasEatenFlightApple; public FoodAppleFlight(int par1, int par2, float par3, boolean par4) { super(par1, par2, par3, par4); hasEatenFlightApple = false; this.setPotionEffect(32, 31, 0, 1.0f); // TODO Auto-generated constructor stub } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister register) { this.itemIcon = register.registerIcon("more_apples:apple_Flight"); } @Override public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if(!par2World.isRemote) { hasEatenFlightApple = true; par3EntityPlayer.addChatMessage("onEaten"); return super.onEaten(par1ItemStack, par2World, par3EntityPlayer); } return par1ItemStack; } @Override public void onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (!par2World.isRemote) { par3EntityPlayer.addChatMessage("onFoodEaten"); super.onFoodEaten(par1ItemStack, par2World, par3EntityPlayer); } } public static boolean getEatenFlightApple() { return hasEatenFlightApple; } public static void setEatenFlightApple(boolean bol) { hasEatenFlightApple = bol; } } Thank for helping, fellow modders. =)
November 6, 201311 yr Hi Curious! Do you know how to use breakpoints? I'd suggest putting a breakpoint into your onEaten and looking at the stack trace to see which thread it's in and who is calling it each time. -TGG
November 7, 201311 yr Author Ok, thanks for the advice, I will research breakpoints and see what I can derive. I'll reply soon to update my situation.
November 7, 201311 yr static boolean hasEatenFlightApple; I don't know why you are doing this, but you shouldn't.
November 12, 201311 yr Author I couldn't find anything wrong. I went through each command,by pressing F6, being run and never saw my code being executed twice. Any suggestions? =\
November 13, 201311 yr Hi So - if you set your breakpoint in onEaten, what do you see in the stack trace? Should look something like this Server thread@2890, prio=5, in group 'main', status: 'RUNNING' at net.minecraft.item.ItemFood.onEaten(ItemFood.java:56) at net.minecraft.item.ItemStack.onFoodEaten(ItemStack.java:181) at net.minecraft.entity.player.EntityPlayer.onItemUseFinish(EntityPlayer.java:467) at net.minecraft.entity.player.EntityPlayerMP.onItemUseFinish(EntityPlayerMP.java:903) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:296) at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:324) at net.minecraft.network.NetServerHandler.handleFlying(NetServerHandler.java:301) at net.minecraft.network.packet.Packet10Flying.processPacket(Packet10Flying.java:51) at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:138) at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54) at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:689) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:585) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) Then hit resume and it will break again immediately (assuming your code really is being called twice), then look at the stack trace again and see if it is being called from a different place. -TGG
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.