Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

uglyluigi

Members
  • Joined

  • Last visited

  1. It sounds like each time you're returning a new ItemStack which is what usually causes the hotbar tooltip to appear. Try returning the same item stack you started with. Edit: I've found a solution. You can disable held item tooltips on the fly with: Minecraft.getMinecraft().gameSettings.heldItemTooltips = false; And then just set it to true after you perform your updates.
  2. uglyluigi changed their profile photo
  3. I'm so silly. I didn't put that together for whatever reason. Who'd've thought the NBT conditional and modifying the NBTs were related?? Not me, apparently. Anyway, this is the boolean method now: @Override public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { return oldStack.getItem() != newStack.getItem(); } Which is what I assumed you meant. This works as desired and stops the reequip animation from taking place while allowing the drinik animation to begin. I believe I've devised a solution that simply sets a flag to true while ignoring updates (so the onUpdate method just returns if the flag is true) after a right click and then resumes NBT updates after the item use is complete. In order to help anyone else who may stumble upon this topic, this is what my code ended up being: package ugly.HeckingTea.items; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.Event; import ugly.HeckingTea.items.effects.EventSipsTea; import ugly.HeckingTea.items.effects.TeaEffect; import ugly.HeckingTea.proxy.TeaModEffectHandler; public class ItemDrinkableTea extends ItemTeaItem { private final TeaEffect effect; public boolean IGNORE_NBT_UPDATES = false; //The new flag, used in subclasses that are consumable but also undergo NBT updates each tick public ItemDrinkableTea(String name, TeaEffect teaEffect) { super(name, 1); this.effect = teaEffect; } @Override public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { IGNORE_NBT_UPDATES = false; return stack; } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { IGNORE_NBT_UPDATES = true; playerIn.setActiveHand(handIn); return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); } @Override public EnumAction getItemUseAction(ItemStack stack) { MinecraftForge.EVENT_BUS.post(new EventSipsTea((ItemDrinkableTea) stack.getItem())); return EnumAction.DRINK; } public TeaEffect getEffect() { return effect; } @Override public int getMaxItemUseDuration(ItemStack stack) { return 16; } } package ugly.HeckingTea.items; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import ugly.HeckingTea.items.effects.TeaEffect; import javax.annotation.Nullable; import java.util.List; public class ItemHotWater extends ItemDrinkableTea { //NOTE: IGNORE_NBT_UPDATES is a field inherited and controlled by the parent class ItemDrinkableTea. public ItemHotWater(String name) { super(name, TeaEffect.teaEffect1); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { super.addInformation(stack, worldIn, tooltip, flagIn); if (stack.hasTagCompound() && stack.getTagCompound().hasKey("FTemp")) { tooltip.add("Temp: " + Math.round(stack.getTagCompound().getFloat("FTemp")) + "°F"); } } @Override public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { return oldStack.getItem() != newStack.getItem(); } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); if (IGNORE_NBT_UPDATES) return; NBTTagCompound nbt; if (stack.hasTagCompound()) { nbt = stack.getTagCompound(); } else { nbt = new NBTTagCompound(); } if (nbt.hasKey("FTemp")) { nbt.setFloat("FTemp", nbt.getFloat("FTemp") - 0.005F); } else { nbt.setFloat("FTemp", 212.0F); stack.setTagCompound(nbt); } } } So my issue is resolved. However, if you don't mind me asking, as I'm a bit of a Forge noob, what are you referring to when you recommend using "capabilities?" Is this somehow related to the "capabilities" field in the EntityPlayer class, and what solution did you have in mind that used it? Like I said I'm a bit of a Forge noob and I'm trying to soak up as much info as possible because the last time I used Forge it didn't even have the event bus system as it exists now (which is really intuitive by the way). Thanks!!
  4. OK, I have made some progress. I did what you said and then I made some changes to ItemDrinkableTea in the onItemRightClick method and made the ActionResult it returns contain an EnumActionResult.PASS. Since that I have located the method calls that are causing the animation to cancel, and it's lines 57 and 59 of ItemHotWater. Apparently updating an NBT value cancels a use animation. My first idea is to check if the item is being used and simply do not update the tag values while this is happening, but I am unaware of a field or method that is capable of giving me this information. I'm going to include both files to give the most complete picture. package ugly.HeckingTea.items; import net.minecraft.client.Minecraft; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import ugly.HeckingTea.HeckingTeaMain; import ugly.HeckingTea.items.effects.TeaEffect; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; public class ItemHotWater extends ItemDrinkableTea { public ItemHotWater(String name) { super(name, TeaEffect.teaEffect1); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { super.addInformation(stack, worldIn, tooltip, flagIn); if (stack.hasTagCompound() && stack.getTagCompound().hasKey("FTemp")) { tooltip.add("Temp: " + Math.round(stack.getTagCompound().getFloat("FTemp")) + "°F"); } } @Override public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { NBTTagCompound tagCompound = oldStack.getTagCompound(), tagCompound2 = newStack.getTagCompound(); return !tagCompound.equals(tagCompound2); } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); NBTTagCompound nbt; if (stack.hasTagCompound()) { nbt = stack.getTagCompound(); } else { nbt = new NBTTagCompound(); } if (nbt.hasKey("FTemp")) { nbt.setFloat("FTemp", nbt.getFloat("FTemp") - 0.005F); } else { nbt.setFloat("FTemp", 212.0F); stack.setTagCompound(nbt); } } } package ugly.HeckingTea.items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.Event; import ugly.HeckingTea.items.effects.EventSipsTea; import ugly.HeckingTea.items.effects.TeaEffect; import ugly.HeckingTea.proxy.TeaModEffectHandler; public class ItemDrinkableTea extends ItemTeaItem { private final TeaEffect effect; public ItemDrinkableTea(String name, TeaEffect teaEffect) { super(name, 1); this.effect = teaEffect; } @Override public EnumAction getItemUseAction(ItemStack stack) { MinecraftForge.EVENT_BUS.post(new EventSipsTea((ItemDrinkableTea) stack.getItem())); return EnumAction.DRINK; } public TeaEffect getEffect() { return effect; } @Override public int getMaxItemUseDuration(ItemStack stack) { return 32; } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { playerIn.setActiveHand(handIn); return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); } } Like I said, if I remove both lines that set NBT values, the problem is "solved" in that the item is consumable and the reequip animation does not occur, but obviously the NBT values will no longer update. I'll continue looking for a solution but I would appreciate some input because this is a rather weird situation since I must be able to write to these tags.
  5. Hmm, I tried this and it got the reequip to stop happening each time the tooltip updates, but the drink animation still appears to be canceled midway through each time. I suspected the tooltip updates mid-animation but removing them does not fix the issue, however if I continue to hold right click it gets to different parts of the animation each time and sometimes even makes it to the first sipping sound. Any ideas? Edit: it appears you edited your post and I had not refreshed to see the edit, I am going to try your solution and report back.
  6. Hi! This is my first post here. Currently, I'm making a mod that allows you to brew various teas at various temperatures. A feature of this mod is that when you boil water in a furnace, it begins cooling when you take it out (the temperature is stored in an NBTTag and each tick a small amount of temperature is removed. Eventually it'll have a temperature that just causes it to return to a normal cup of water). Since tooltip updates cause a reequip animation to be fired and the tooltip is updated every tick, the item undergoes the reequip animation around 20 times a second which is very distracting. I was able to fix this issue for a while by overriding the shouldCauseReequipAnimation to always return false, however now that I added the ability to actually drink the hot water, I ran into a weird issue. Apparently, if shouldCauseReequipAnimation always returns false, if your item is a drink, it cannot undergo the drinking animation and will not be consumed. If I simply return super.shouldCauseReequipAnimation, it's pretty much the same issue since the game considers the item stacks different because of the slightly different tooltips. The goal is to disable the reequip animation but allow the item to undergo the drinking animation, however the only way I can think of accomplishing this is to ignore tooltip changes but let everything else pass. Unfortunately, this is a weird edge case and I understandably did not find a straightforward way to do this. Any help or advice would be greatly appreciated. package ugly.HeckingTea.items; import net.minecraft.client.Minecraft; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import ugly.HeckingTea.HeckingTeaMain; import ugly.HeckingTea.items.effects.TeaEffect; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; //ItemDrinkableTea is the parent class containing the getItemUseAction and getMaxItemUseDuration overrides. public class ItemHotWater extends ItemDrinkableTea { public ItemHotWater(String name) { super(name, TeaEffect.teaEffect1); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { super.addInformation(stack, worldIn, tooltip, flagIn); if (stack.hasTagCompound() && stack.getTagCompound().hasKey("FTemp")) { tooltip.add("Temp: " + Math.round(stack.getTagCompound().getFloat("FTemp")) + "°F"); } } @Override public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { //return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged); return false; } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); NBTTagCompound nbt; if (stack.hasTagCompound()) { nbt = stack.getTagCompound(); } else { nbt = new NBTTagCompound(); } if (nbt.hasKey("FTemp")) { nbt.setFloat("FTemp", nbt.getFloat("FTemp") - 0.005F); } else { nbt.setFloat("FTemp", 212.0F); stack.setTagCompound(nbt); } } }

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.