Is Player blocking with a shield?

Hello together,

I would like to know, if there is any way to recognise if a player is currently blocking with a shield.

Maybe an event where I could listen for or an attribute that is changing?

Regards

Sascha

Player player;
Optional<ItemStackSnapshot> opActive = player.get(Keys.ACTIVE_ITEM);

If it is present then the player could be blocking, eating. Etc. After that check it is a shield.

As for event wise.

ChangeDataHolderEvent.ValueChanged

Is the event to listen to, however there are a few keys it does not fire for, not sure if that key it does fire for or not. If it doesnt fire send a issue to the sponge github page as it should be firing

1 Like

Thanks for the fast answer. I will give both ways a try and will come back after :slight_smile:

Unfortunately the event does not trigger when the active item key changes.

Nevertheless, checking for the active item works perfectly fine for my cases.

Thank you very much for the help!

1 Like