PlotSquared icon indicating copy to clipboard operation
PlotSquared copied to clipboard

Prevent headless pistons deleting walls

Open traksag opened this issue 3 years ago • 3 comments

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 PISTON instead of MOVING_PISTON in this event.
  • It is somewhat important to only handle sticky pistons with no blocks in front of them, because BlockPistonRetractEvent#getDirection is 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.

traksag avatar Jun 30 '22 23:06 traksag

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)

dordsor21 avatar Jul 06 '22 14:07 dordsor21

@traksag Do you want to address the PR feedback?

NotMyFault avatar Aug 19 '22 17:08 NotMyFault

Sure, I kinda forgot about it. Will probably crack something out over the weekend.

traksag avatar Aug 20 '22 00:08 traksag