SteamWar/BauSystem2.0
Archiviert
12
0

Fix edge case for PistonCalculator
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-08-28 17:06:24 +02:00
Ursprung 776dd84668
Commit f63d529b55

Datei anzeigen

@ -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<Block> 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<Block> blockSet, List<Block> toCalc, AtomicBoolean unmovable) {
private void calcDirection(Block origin, Block blockOrigin, Block calcOrigin, Block ignore, BlockFace facing, BlockFace direction, Set<Block> blockSet, List<Block> 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);
}