OldCombatMechanics

OldCombatMechanics

46.1k Downloads

A way to remove the list of interactable blocks in the config

blubbarbs opened this issue ยท 6 comments

commented

Hello, something that I noticed about this plugin is that it uses a list of interactable blocks in the config in order to check whether to shield when right clicking a block or not. I made a plugin that replicated old PVP myself some time back, and I found a way to solve it without needing such a list, which becomes a hassle to maintain the more blocks are added to Minecraft.

The PlayerInteractEvent has the potential to fire 2 times, one for each hand. If the player interacted with a block that is interactable, however, the event will not fire at all for the off-hand. Thus, a simple guard clause would be needed in the PlayerInteractEvent listener:

if (event.hasBlock() && event.getHand() == EquipmentSlot.HAND) return;

This catches the right-click on an interactable block. If the block was non-interactable, the event would fire again for the off-hand, at which point you know that the block was non-interactable and the logic for bringing up the shield can proceed as normal. That's all, I hope that this can help.

commented

Interesting, are these methods available in the 1.9 spigot API too? Also what do you mean about having two events, that there's two of the same type of event fired if the block is interactable?

commented

I haven't tested this in 1.9; however, this was working in late 2019 when I implemented it and I have no reason to assume that this wouldn't work in 1.9. And yes, two events of the PlayerInteractEvent type get fired, but if there was a clicked block and the block is non-interactable. If the block is interactable, the PlayerInteractEvent will only fire for the main hand.

commented

Interesting, are these methods available in the 1.9 spigot API too? Also what do you mean about having two events, that there's two of the same type of event fired if the block is interactable?

In 1.10, yes. I don't have test it on 1.9

commented

Hmm yes it seems both methods are available in 1.9. I will look into this after I am done rewriting the damage calculation components.

commented

Actually do you mind if I open a PR? I don't think the feature should take that long to implement

commented

So I just tested this with 1.19 and it doesn't seem to be the case at all. If I right click on a block the PlayerInteractEvent will fire, event.hasBlock() will be true and the hand will be HAND, but the event is not fired again for the offhand (which is currently empty). @blubbarbs @detobel36 did I misunderstand something in the way you are handling this?