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