Posted September 1, 20169 yr i am having a bit of a issue. i made a nbt tag compound for my item. the problem is i tried to make it a cool down. The cooldown is always 0 for some reason even if i try to set it. @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int i, boolean flag) { super.onUpdate(itemStack, world, entity, i, flag); if (!world.isRemote) { NBTTagCompound nbtDataCompund; if (itemStack.hasTagCompound()) { nbtDataCompund = itemStack.getTagCompound(); } else { nbtDataCompund = new NBTTagCompound(); } int coolDown = nbtDataCompund.getInteger("coolDown"); if (coolDown > 0) { --coolDown; nbtDataCompund.setInteger("coolDown", coolDown); } } } @Override public boolean itemInteractionForEntity(ItemStack itemStack, EntityPlayer entityPlayer, EntityLivingBase entity, EnumHand hand) { NBTTagCompound nbt; if (itemStack.hasTagCompound()) { nbt = itemStack.getTagCompound(); } else { nbt = new NBTTagCompound(); } int coolDown = nbt.getInteger("coolDown"); if (coolDown > 0) { return false; } if (coolDown == 0) { if (entity instanceof EntityMob) { if (itemStack.getItemDamage() > 0) { entity.setHealth(0.0F); nbt.setInteger("coolDown", 180); } } } }
September 1, 20169 yr i am having a bit of a issue. i made a nbt tag compound for my item. the problem is i tried to make it a cool down. The cooldown is always 0 for some reason even if i try to set it. @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int i, boolean flag) { super.onUpdate(itemStack, world, entity, i, flag); if (!world.isRemote) { NBTTagCompound nbtDataCompund; if (itemStack.hasTagCompound()) { nbtDataCompund = itemStack.getTagCompound(); } else { nbtDataCompund = new NBTTagCompound(); } int coolDown = nbtDataCompund.getInteger("coolDown"); if (coolDown > 0) { --coolDown; nbtDataCompund.setInteger("coolDown", coolDown); } } } @Override public boolean itemInteractionForEntity(ItemStack itemStack, EntityPlayer entityPlayer, EntityLivingBase entity, EnumHand hand) { NBTTagCompound nbt; if (itemStack.hasTagCompound()) { nbt = itemStack.getTagCompound(); } else { nbt = new NBTTagCompound(); } int coolDown = nbt.getInteger("coolDown"); if (coolDown > 0) { return false; } if (coolDown == 0) { if (entity instanceof EntityMob) { if (itemStack.getItemDamage() > 0) { entity.setHealth(0.0F); nbt.setInteger("coolDown", 180); } } } } You never set it to be anything other than 0... VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
September 1, 20169 yr Look near the bottom Ok is the Item damagable? Post the whole class please. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
September 1, 20169 yr Author your not looking " nbt.setInteger("coolDown", 180); " there is the part where it is set in the code
September 1, 20169 yr He's asking because of 'if(itemStack.getItemDamage() > 0)', that's the only place you set the nbt, so that's where you should be looking, to see if it's actually getting run.
September 1, 20169 yr Author it is but here is the whole code after working on it a bit. @Override public boolean itemInteractionForEntity(ItemStack itemStack, EntityPlayer entityPlayer, EntityLivingBase entity, EnumHand hand) { NBTTagCompound nbt; if (itemStack.hasTagCompound()) { nbt = itemStack.getTagCompound(); } else { nbt = new NBTTagCompound(); } int coolDown = nbt.getInteger("coolDown"); if (coolDown > 0) { return false; } if (coolDown == 0) { if (entity instanceof EntityMob) { if (itemStack.getItemDamage() > 0) { entity.setHealth(0.0F); nbt.setInteger("coolDown", 180); if (!entity.worldObj.isRemote) { entityPlayer.addChatMessage(new TextComponentString(TextFormatting.GRAY + "Soul Absurbed!")); } itemStack.damageItem(-1, entityPlayer); return true; } else { if (!entity.worldObj.isRemote) { entityPlayer.addChatMessage(new TextComponentString(TextFormatting.GRAY + "The Magical Stone seems to be full?")); entityPlayer.addChatMessage(new TextComponentString(TextFormatting.GRAY + "It seems to be useless now.")); entityPlayer.addChatMessage(new TextComponentString(TextFormatting.GRAY + "I wonder whats inside?")); } return true; } } else if (!entity.worldObj.isRemote) { entityPlayer.addChatMessage(new TextComponentString(TextFormatting.GRAY + "Why has this stoped working?")); } } else { entityPlayer.addChatMessage(new TextComponentString(TextFormatting.GRAY + "Why has this stoped working?")); } return false; } ignore all the isRemote it is there so that the message doesn't get displayed twice
September 1, 20169 yr You should probably post the whole item's code, not just the one function, and use a service like pastebin or github's gist, with the syntax highlighting set to Java, (name the file xyz.java for gist) it makes code a lot easier to read.
September 1, 20169 yr Won't be the solution, but doing 'damageItem' with a value of -1 won't do anything, that function calls 'attemptDamageItem' which explicitly checks if the int passed in is above 0. [edit] ...Ok wow I really overlooked something, you're not writing the altered NBT to the stack's NBT. That...might be a problem
September 1, 20169 yr not writing ? This: if (itemStack.hasTagCompound()) { nbtDataCompund = itemStack.getTagCompound(); } else { nbtDataCompund = new NBTTagCompound(); } If the stack doesn't have NBT, you create an NBT tag. you never give the item stack this new NBT. It exists only as a local variable and is discarded when the method returns. 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.
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.