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

Started by Gabriel0314 on

Topic category: Help with MCreator software

Active 3 years ago
Joined Aug 2019
Points:
707

User statistics:

  • Modifications: 1
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 13
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!

Active 11 months ago
Joined Dec 2020
Points:
1164

User statistics:

  • Modifications: 2
  • Forum topics: 28
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 819
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).

Active 3 years ago
Joined Aug 2019
Points:
707

User statistics:

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

Thank You this Works

Active 3 years ago
Joined Aug 2019
Points:
707

User statistics:

  • Modifications: 1
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 13
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

 

Active 2 months ago
Joined Aug 2020
Points:
937

User statistics:

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

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

Active 2 months ago
Joined Aug 2020
Points:
937

User statistics:

  • Modifications: 3
  • Forum topics: 20
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 379
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

Active 3 years ago
Joined Aug 2019
Points:
707

User statistics:

  • Modifications: 1
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 13
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

 

Active 3 years ago
Joined Aug 2019
Points:
707

User statistics:

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

oh wait i figured it out

 

Active 2 months ago
Joined Aug 2020
Points:
937

User statistics:

  • Modifications: 3
  • Forum topics: 20
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 379
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 ^^

Active 2 months ago
Joined Aug 2020
Points:
937

User statistics:

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

demonstration of how it would look like*, sorry