MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create an item that when interacting with a block, destroys a diamond in your inventory"
/* This mod creates an item that destroys a diamond from the player's inventory when interacting with a block. */ public class DiamondDestroyerItem extends Item { public DiamondDestroyerItem(Properties properties) { super(properties); } @Override public ActionResultType useOn(ItemUseContext context) { PlayerEntity player = context.getPlayer(); if (player == null) { return ActionResultType.PASS; } /* Check if the player has a diamond in their inventory */ for (int i = 0; i < player.inventory.getContainerSize(); i++) { ItemStack stack = player.inventory.getItem(i); if (stack.getItem() == Items.DIAMOND) { /* If a diamond is found, decrease the stack size by 1 and return success */ stack.shrink(1); return ActionResultType.SUCCESS; } } /* If no diamond is found, return pass */ return ActionResultType.PASS; } }