How do you check if a player is holding Lapis in their hand?

Started by SingularityV3 on

Topic category: Advanced modding

Last seen on 22:54, 17. Sep 2019
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do you check if a player is holding Lapis in their hand?

I am making a block that when you right click on it with certain objects in your hand it adds other items to your inventory. The problem is that Lapis has metadata, and I am not sure how to check for metadata that is not in the ItemStack() method. My current code checks for ANY dye, then gives you a piece of Lapis:

if (entity.inventory.getCurrentItem() != null && entity.inventory.getCurrentItem().getItem() == Items.DYE) {
if (entity instanceof EntityPlayer)
((EntityPlayer) entity).inventory.addItemStackToInventory(new ItemStack(Items.DYE, 1, 4));

 

Last seen on 03:03, 6. Feb 2024
Joined Apr 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try On block rightclicked do…
Sun, 04/08/2018 - 07:16

Try On block rightclicked
do what ever you want to do there and change (in All Cases) to itemInPlayersHand[] == item

that should do

Last seen on 22:54, 17. Sep 2019
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I have it so that On Block…
Sun, 04/08/2018 - 12:14

I have it so that On Block Right Clicked it checks for the rest of the items, and I am manually adding in Lapis because MCreator does not support any dye other than the generic "Dye" in the context of events; therefor if I did that it would check for any dye in the player's hand then give you an Ink Sack.

Last seen on 22:54, 17. Sep 2019
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry I spelled "Therefore"…
Sun, 04/08/2018 - 12:16

Sorry I spelled "Therefore" wrong.

Last seen on 03:03, 6. Feb 2024
Joined Apr 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try this:if (entity…
Sun, 04/08/2018 - 14:19

Try this:
if (entity.inventory.getCurrentItem() != null && entity.inventory.getCurrentItem().getItem() == Items.LAPIS) { if (entity instanceof EntityPlayer) ((EntityPlayer) entity).inventory.addItemStackToInventory(new ItemStack(Items.LAPIS, 1, 4));

Last seen on 22:54, 17. Sep 2019
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Already tried that. Lapis is…
Sun, 04/08/2018 - 16:14

Already tried that. Lapis is a metadata of the more general class "DYE", and has no ID of it's own. The only reason the "new ItemStack(Items.DYE, 1, 4)" code works is because ItemStack() takes metadata as a parameter (The 4), so it gives you a dye with metadata of 4, which happens to be Lapis. The reason this code does not work in the context of "entity.inventory.getCurrentItem().getItem() == Items.LAPIS", is that it is an If statement and, therefore, does not allow for the inclusion of parameters in general.