How to I check if a player is not holding anything?

Started by Gabriel0314 on

Topic category: Help with MCreator software

Last seen on 02:27, 8. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to I check if a player is not holding anything?

I am making a brawler class and I want to make sure the player is attacking with his fist. I don't know how to check if a player is not holding anything. Please Help!

You can try to check if …
Sat, 07/17/2021 - 22:11

You can try to check if "item in main-hand" is "Air". Not sure if it works (didn't test that myself), but it can work since "Air" is usually used for any "empty" element (for example in crafting or GUI).

Last seen on 02:27, 8. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank You this Works
Sun, 07/18/2021 - 02:42

Thank You this Works

Last seen on 02:27, 8. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This stopped working a few…
Tue, 07/27/2021 - 02:03

This stopped working a few days after testing it. :( I need a new solution

 

Last seen on 08:14, 28. Nov 2023
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
try replacing "air" with …
Tue, 07/27/2021 - 02:49

try replacing "air" with "empty itemstack", personally using empty itemstack worked for me

Last seen on 08:14, 28. Nov 2023
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
in code it'd look something…
Tue, 07/27/2021 - 02:58

in code it'd look something like this when checking for "provided itemstack"

if ((itemstack).getItem() == (ItemStack.EMPTY))

or this, when checking for item in mainhand:

if ((((sourceentity instanceof LivingEntity) ? ((LivingEntity) sourceentity).getHeldItemMainhand() : ItemStack.EMPTY).getItem() == (ItemStack.EMPTY)))

or differently, depending on where you use it. but take note that ItemStack.EMPTY should be what we're always gonna be looking for. basically we'd need to check if the item being held is equivalent to ItemStack.EMPTY ("Empty Itemstack" in procedure) as it's what actually tells the game that a certain item is indeed empty; checking for air won't work all the time i believe

Last seen on 02:27, 8. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how do i do this wihout…
Tue, 07/27/2021 - 03:36

how do i do this wihout custom code

im using procedures cus idk how to code

 

Last seen on 02:27, 8. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
oh wait i figured it out  
Tue, 07/27/2021 - 03:45

oh wait i figured it out

 

Last seen on 08:14, 28. Nov 2023
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
lol yea, in my 2nd comment i…
Tue, 07/27/2021 - 04:22

lol yea, in my 2nd comment i wasn't telling you to code it :P

in my 1st comment i said replace "air" w/ "empty itemstack", that's the only important thing you needed to know; the code is simply a demonstration of how it would like in code, as well as a few technical explanation as to why empty itemstack should be used ^^

Last seen on 08:14, 28. Nov 2023
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
demonstration of how it…
Tue, 07/27/2021 - 04:25

demonstration of how it would look like*, sorry