This PR fixes several issues with the PlayerInteractEvent and the rightClickBlock() and rightClickAir() methods of ItemType.
The following bugs are fixed:
Block clicks fired an additional interact event with left click air (this was checked in PlayerSwingArmHandler and failed because GlowLivingEntity#getTargetBlock returned wrong values)
Right clicking on a block with an unplaceable item (e.g. a nether star) fired an additional right click air event because the client sends the place block and use item packets in this case
When trying to place a placeable block and it fails (e.g. tall grass on stone), the client only sends a use item packet, which only fired a right click air interact. There's a right click block now fired instead (The block and block face values are computed by the UseItemHandler). This includes handling all internal right click actions.
Water behind a wall could be pickup up with a bucket
In some cases, interacting with blocks was possible even when sneaking and a block in the hand. (Solved by requiring both hands to be empty)
Emptying a bucket in survival mode now changes the item type to BUCKET
Implemented rightClickBlock handlers for all ItemTypes which previously depended on rightClickAir even if a block was clicked
Cleaned up boat placement
There still is an issue with this implementation:
When clicking next to an interactable block (e.g. a lever), the lever is still flipped because the current raytrace (BlockIterator) ignores the size of the blocks. Also, the clickedAt vector in the ItemType#rightClickBlock method doesn't have correct values in it because of this problem.
So a proper raytracing method has to be implemented in the future, which would be useful also for other things (like filling a bucket).
Everything regarding the PlayerInteractEvent has been tested in comparison to Spigot behaviour. The results were not equal in all cases, but that's because Spigot isn't handling everything correctly itself ;) (Some interacts even seem quite random).
One difference I noticed was that for right and left click air events, Spigot always used BlockFace.SOUTH whereas we are setting the value to null. So there may be plugins that don't expect a null value here. Should we also set the face to SOUTH (which doesn't really make sense), should we use something more general like BlockFace.SELF or should we still use null?
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.