Prevent headless pistons deleting walls
Overview
Fixes #3716
Description
Cancel the retract event when a sticky piston faces the plot wall (or into a plot area) and retracts with no blocks attached to it. The effect: the plot wall block doesn't get deleted and the headless sticky piston will turn into a normal sticky piston.
Some things to take note of:
- If a headless sticky piston has more than 1 block in front of it, the piston retract event doesn't seem to fire. In that case the block directly in front of the headless piston also doesn't get deleted. So we don't need to worry about this case.
- Headless non-sticky pistons don't seem to delete the block in front of them. So we can ignore non-stickies. Note that non-stickies have block type
PISTONinstead ofMOVING_PISTONin this event. - It is somewhat important to only handle sticky pistons with no blocks in front of them, because
BlockPistonRetractEvent#getDirectionis the direction the blocks move in if the block list is non-empty, and otherwise the facing direction of the piston.
Submitter Checklist
- [x] Make sure you are opening from a topic branch (/feature/fix/docs/ branch (right side)) and not your main branch.
- [x] Ensure that the pull request title represents the desired changelog entry.
- [x] New public fields and methods are annotated with
@since TODO. - [x] I read and followed the contribution guidelines.
A check for the block being outside the min/max build heights of the plot area would also be an idea. See the usages of PlotArea#buildRangeContainsY in other events (I'm assuming the same issue will be present for this case as well)
@traksag Do you want to address the PR feedback?
Sure, I kinda forgot about it. Will probably crack something out over the weekend.