Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.6.4] Food Eating Twice
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
ItsTheRuski

[1.6.4] Food Eating Twice

By ItsTheRuski, November 6, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

ItsTheRuski    2

ItsTheRuski

ItsTheRuski    2

  • Stone Miner
  • ItsTheRuski
  • Members
  • 2
  • 55 posts
Posted November 6, 2013

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

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    711

TheGreyGhost

TheGreyGhost    711

  • Reality Controller
  • TheGreyGhost
  • Members
  • 711
  • 2805 posts
Posted November 6, 2013

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

  • Quote

Share this post


Link to post
Share on other sites

ItsTheRuski    2

ItsTheRuski

ItsTheRuski    2

  • Stone Miner
  • ItsTheRuski
  • Members
  • 2
  • 55 posts
Posted November 7, 2013

Ok, thanks for the advice, I will research breakpoints and see what I can derive. I'll reply soon to update my situation.

  • Quote

Share this post


Link to post
Share on other sites

YSPilot    2

YSPilot

YSPilot    2

  • Tree Puncher
  • YSPilot
  • Members
  • 2
  • 22 posts
Posted November 7, 2013

IDK if it is related, but onFoodEaten and onEaten look exactly the same.

  • Quote

Share this post


Link to post
Share on other sites

GotoLink    381

GotoLink

GotoLink    381

  • World Shaper
  • GotoLink
  • Members
  • 381
  • 2012 posts
Posted November 7, 2013

static boolean hasEatenFlightApple;

I don't know why you are doing this, but you shouldn't.

  • Quote

Share this post


Link to post
Share on other sites

ItsTheRuski    2

ItsTheRuski

ItsTheRuski    2

  • Stone Miner
  • ItsTheRuski
  • Members
  • 2
  • 55 posts
Posted November 7, 2013

The static boolean is used in one of my events to remove fall damage.

  • Quote

Share this post


Link to post
Share on other sites

ItsTheRuski    2

ItsTheRuski

ItsTheRuski    2

  • Stone Miner
  • ItsTheRuski
  • Members
  • 2
  • 55 posts
Posted November 12, 2013

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? =\

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    711

TheGreyGhost

TheGreyGhost    711

  • Reality Controller
  • TheGreyGhost
  • Members
  • 711
  • 2805 posts
Posted November 13, 2013

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

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • SilviaX_92
      Forge having problem loading mods

      By SilviaX_92 · Posted 2 hours ago

      Hi DaemonUmbra, I think I was told to do that by the Pixelmon installation instruction but apparently I misunderstood the wording...   I tried and it worked! Thank you so so much you saved me from a Minecraft without Mods!   Have a wonderful day/night!
    • Draco18s
      MoonPhase help

      By Draco18s · Posted 3 hours ago

      Events don't return values. Second, I'm pretty sure getMoonPhase() is client side only.
    • GatoLeyo
      MoonPhase help

      By GatoLeyo · Posted 3 hours ago

      Im new at modding so probably this have an obvious error but plz somebody tell me how can i make this works, it is intended to return a value in relation to the moon phase       public float endWorldTick(TickEvent.WorldTickEvent event)      {         float x = 0;         if(event.side.isServer() && event.phase == TickEvent.Phase.END)          {             World world = event.world;             if(world.provider.getDimension() == 0) {                 if(world.getMoonPhase() == 1.0f)                  {                   x = 15.0f;                 }             }         }         return x;     }  
    • DaemonUmbra
      Can't see anything on minecraft menu screen except for the bottom left corner

      By DaemonUmbra · Posted 3 hours ago

      Please don't Necro old threads, if you have an issue make your own.
    • DaemonUmbra
      Forge having problem loading mods

      By DaemonUmbra · Posted 3 hours ago

      You changed "Game Directory" to your mods folder. The Game Directory is supposed to be the folder that contains the mods folder, .minecraft by default
  • Topics

    • SilviaX_92
      4
      Forge having problem loading mods

      By SilviaX_92
      Started 7 hours ago

    • GatoLeyo
      1
      MoonPhase help

      By GatoLeyo
      Started 3 hours ago

    • florgonn
      4
      Can't see anything on minecraft menu screen except for the bottom left corner

      By florgonn
      Started July 30, 2014

    • Casual
      1
      1.12.2 crash on game start

      By Casual
      Started 4 hours ago

    • PulseBeat_02
      14
      [1.12.2] Forge Crashes While Just Loading Into Loading Screen

      By PulseBeat_02
      Started December 13, 2018

  • Who's Online (See full list)

    • DaemonUmbra
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.6.4] Food Eating Twice
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community