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.

Featured Replies

Posted

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);

                                }

                          }

                }

        }

 

 

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.

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.

  • 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

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.

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 :P

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.

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

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.