Jump to content

Recommended Posts

Posted

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. =)

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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