Posted February 3, 20232 yr Thank you all in advance for your help! I create a simple class for the item, here, if the player makes a right click, he gets a random item, and at the end I want the item to decrease the strength and when the strength is 0, the item is destroyed. But when I right click, the strength goes into the negative numbers and the item doesn't break : public class DiarubiumWand extends Item { public DiarubiumWand(Properties pProperties) { super(pProperties); } @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { if(pLevel.isClientSide) { int random = (int) Math.floor(1 + Math.random() * 3); pPlayer.sendMessage(new TextComponent("Value: "+ random), pPlayer.getUUID()); if(random == 1) pPlayer.addItem(Items.DIAMOND.getDefaultInstance()); else if(random == 2) pPlayer.addItem(Blocks.DIRT.asItem().getDefaultInstance()); else if(random == 3) pPlayer.addItem(ModItems.DIARUBIUM_RAW.get().getDefaultInstance()); pPlayer.getItemInHand(InteractionHand.MAIN_HAND).hurt(1, new Random(), null); } return super.use(pLevel, pPlayer, pUsedHand); } } This is item registrator: public static final RegistryObject<Item> DIARUBIUM_WAND = ITEMS.register( "diarubium_wand", () -> new DiarubiumWand( new Item.Properties() .tab(Diarubium.TAB) .durability(10))); Edited February 3, 20232 yr by Sniklz
February 3, 20232 yr You need a method that checks how much damage your item has taken, and when that damage equals the item's max durability, it gets removed from the item slot.
February 3, 20232 yr Author Im found how to make it: pPlayer.getItemInHand(pUsedHand) .hurtAndBreak(1, pPlayer, (player -> player.broadcastBreakEvent(player.getUsedItemHand())));
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.