2
\$\begingroup\$

I am modding Minecraft 1.8 using Eclipse with Forge, and I just wondered, is there a way to drain durability from a battery, for instance, instead of a piece of armor when hit. I have tried things like getting an item from the player's inventory and attempting to reduce its durability, so that would be a possibility, however, I was unable to find a way to do so?

\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

You can use the field inventory in the player class to help you. Using the method player.inventory.hasItemStack(ItemStack); to test if it contains the battery item. An example:

@Override
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player,
        Entity entity) {
  if (player.inventory.hasItemStack(Items.battery)) {
    //Do something to it
    return false;
  } else {
    return true;
  }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .