From f63d529b55a9986973cc7d296018630153d4a259 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 28 Aug 2022 17:06:24 +0200 Subject: [PATCH] Fix edge case for PistonCalculator Signed-off-by: yoyosource --- .../features/util/PistonCalculator.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java index 130af74e..fba74619 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java @@ -33,13 +33,15 @@ import org.bukkit.block.PistonMoveReaction; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Piston; -import org.bukkit.block.data.type.PistonHead; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.*; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @Linked(LinkageType.LISTENER) @@ -71,7 +73,7 @@ public class PistonCalculator implements Listener { if (facing != direction) calcOrigin = origin.getRelative(facing, 3); List toCalc = new LinkedList<>(); - calcDirection(origin, calcOrigin, facing != direction ? origin.getRelative(facing) : null, facing, direction, blockSet, toCalc, unmovable); + calcDirection(origin, null, calcOrigin, facing != direction ? origin.getRelative(facing) : null, facing, direction, blockSet, toCalc, unmovable); while (!toCalc.isEmpty()) { Block current = toCalc.remove(0); @@ -87,7 +89,7 @@ public class PistonCalculator implements Listener { if (!isPiston(block) && (block.getPistonMoveReaction() == PistonMoveReaction.BLOCK || block.getPistonMoveReaction() == PistonMoveReaction.IGNORE || block.getPistonMoveReaction() == PistonMoveReaction.PUSH_ONLY || block.getState() instanceof TileState)) continue; if (block.getType() != oppositeType) { if (!blockSet.contains(block)) toCalc.add(block); - calcDirection(null, block, null, facing, direction, blockSet, toCalc, unmovable); + calcDirection(null, origin, block, null, facing, direction, blockSet, toCalc, unmovable); } } } @@ -97,7 +99,7 @@ public class PistonCalculator implements Listener { return new CalculationResult(blockSet.size(), blockSet.size() > 12, unmovable.get()); } - private void calcDirection(Block origin, Block calcOrigin, Block ignore, BlockFace facing, BlockFace direction, Set blockSet, List toCalc, AtomicBoolean unmovable) { + private void calcDirection(Block origin, Block blockOrigin, Block calcOrigin, Block ignore, BlockFace facing, BlockFace direction, Set blockSet, List toCalc, AtomicBoolean unmovable) { for (int i = 1; i < 13; i++) { Block block = calcOrigin.getRelative(direction, i); if (block.equals(ignore)) return; @@ -107,6 +109,10 @@ public class PistonCalculator implements Listener { return; } if (block.getType().isAir()) return; + if (facing == direction && block.equals(blockOrigin)) { + unmovable.set(true); + return; + } if (facing != direction && (block.equals(origin) || block.getRelative(facing.getOppositeFace()).equals(origin))) return; if (!blockSet.contains(block)) toCalc.add(block); }