Posted February 19, 20178 yr So I have an item that I want to make lost a durability every 5 seconds, so every 100 ticks. I've done some looking around about implementing a tick counter into NBT to help track this, but so far I have been unsuccessful in getting this to work(as entire functions that are present in the tutorial are not there any more).
February 19, 20178 yr Override the onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {} method of your Item. It's called every tick the Item is in the players inventory.
February 19, 20178 yr Define "doesn't work." Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 19, 20178 yr 2 hours ago, TheSunCat said: I tried that, and adding a counter, but it refuses to work. I done that once before and it act perfect: Spoiler @Override public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { return false; } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if(entityIn instanceof EntityLivingBase) { if(!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } if (stack.getTagCompound().hasKey("TickCounter")) { int tickCounter = stack.getTagCompound().getInteger("TickCounter"); if (tickCounter <= 0) { stack.damageItem(1, ((EntityLivingBase) entityIn)); stack.getTagCompound().setInteger("TickCounter", 100); } else { stack.getTagCompound().setInteger("TickCounter", --tickCounter); } } else { stack.getTagCompound().setInteger("TickCounter", 100); } } } Edited February 19, 20178 yr by Lhykos
February 19, 20178 yr Author How do you go about adding the NBT tag to an item? and should i put it in the onCreated meathod?
February 19, 20178 yr Author Whenever I load a world with the code above in my item class I crash with this error. Spoiler [09:40:09] [Server thread/ERROR]: Encountered an unexpected exception net.minecraft.util.ReportedException: Ticking player at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:210) ~[NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:817) ~[MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121] Caused by: java.lang.NullPointerException at com.Frost2779.AWillToLive.Items.ItemFullWill.onUpdate(ItemFullWill.java:43) ~[ItemFullWill.class:?] at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:503) ~[ItemStack.class:?] at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:390) ~[InventoryPlayer.class:?] at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:563) ~[EntityPlayer.class:?] at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2292) ~[EntityLivingBase.class:?] at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:258) ~[EntityPlayer.class:?] at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:367) ~[EntityPlayerMP.class:?] at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:176) ~[NetHandlerPlayServer.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:218) ~[NetworkDispatcher$1.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:308) ~[NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:195) ~[NetworkSystem.class:?] ... 5 more
February 19, 20178 yr Crash is useless without your Item class. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 19, 20178 yr Author My mistake package com.Frost2779.AWillToLive.Items; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ItemFullWill extends Item { public ItemFullWill(){ this.setMaxDamage(100); this.setMaxStackSize(1); } @Override public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { return false; } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if(entityIn instanceof EntityLivingBase) { if (stack.hasTagCompound() && stack.getTagCompound().hasKey("TickCounter")) { int tickCounter = stack.getTagCompound().getInteger("TickCounter"); if (tickCounter <= 0) { stack.damageItem(1, ((EntityLivingBase) entityIn)); stack.getTagCompound().setInteger("TickCounter", 100); } else { stack.getTagCompound().setInteger("TickCounter", --tickCounter); } } else { stack.getTagCompound().setInteger("TickCounter", 100); } } } }
February 19, 20178 yr 1 hour ago, TheSunCat said: You need to check if the NBTTag is not null. Oh, I didn't see that I not checked that. I fix that better in my code.
February 19, 20178 yr Author 3 minutes ago, Lhykos said: Oh, I didn't see that I not checked that. I fix that better in my code. What in your code from earlier should i change?
February 19, 20178 yr 7 minutes ago, Frost2779 said: What in your code from earlier should i change? I already changed it. Just look in the code from my earlier post.
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.