From cd80c0a741fb904d161609e75b9e17b5bd6c4d5d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 20 Jun 2021 13:04:13 +0200 Subject: [PATCH] Fix ObserverTracerCommand Fix ObserverTracer Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 + .../features/observer/ObserverTracer.java | 132 ++++++++++++++---- .../observer/ObserverTracerCommand.java | 10 ++ 3 files changed, 119 insertions(+), 25 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 565a173e..e1cac3fd 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -314,6 +314,8 @@ LOADTIMER_SUMARY_STATS_FREQ=§7Belade Frequenz: §e{0}/m§8, §7Schuss Frequenz: # Observer OBSERVER_HELP = §7Rechts-Klicke einen Observer um den Trace zu bekommen. Hierfür müssen Flammenpartikel an sein. Die Partikel werden im Block angezeigt. OBSERVER_DELETE = §7Observer Trace gelöscht +OBSERVER_RETRACE_DONE = §7Observer Trace neu berechnet +OBSERVER_RETRACE_NO-TRACE = §7Kein Observer Trace zum neu berechnen # Other OTHER_ITEMS_TELEPORT_NAME=§eTeleporter diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java index 655e82b8..16427962 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -71,27 +71,30 @@ public class ObserverTracer { seen.add(b.getLocation()); spawnParticle(player, b.getLocation(), b); - switch (b.getType()) { - case OBSERVER: - calculateObserver(b); - break; - default: - BlockData blockData = b.getBlockData(); - if (blockData instanceof Door) { - if (((Door) blockData).getHalf() == Bisected.Half.BOTTOM) { - blockList.add(b.getLocation().add(0, 1, 0).getBlock()); - } else { - blockList.add(b.getLocation().add(0, -1, 0).getBlock()); - } - } - if (checkAllowed(b, blockData)) { - calculateSpecial(b); - break; - } - if (b.getType().isBlock() && b.getType().isSolid()) { - calculateSolidBlock(b); - } - break; + if (b.getType() == Material.OBSERVER) { + calculateObserver(b); + continue; + } + + BlockData blockData = b.getBlockData(); + if (blockData instanceof Fence) { + calculateSimple(b); + continue; + } + + if (blockData instanceof Door) { + if (((Door) blockData).getHalf() == Bisected.Half.BOTTOM) { + blockList.add(b.getLocation().add(0, 1, 0).getBlock()); + } else { + blockList.add(b.getLocation().add(0, -1, 0).getBlock()); + } + } + if (checkAllowed(b, blockData)) { + calculateSpecial(b); + } + + if (b.getType().isBlock() && b.getType().isSolid() && b.getType().isOccluding()) { + calculateSolidBlock(b); } } } @@ -125,6 +128,27 @@ public class ObserverTracer { blockList.add(b); } } + if (observer.getFacing() == BlockFace.UP) { + Location location = block.getLocation(); + location.add(0, -2, 0); + if (location.getY() >= 0) { + Block b = location.getBlock(); + if (b.getType() == Material.DROPPER || b.getType() == Material.DISPENSER) { + blockList.add(b); + } + } + } + if (observer.getFacing() != BlockFace.UP && observer.getFacing() != BlockFace.DOWN) { + Location location = block.getLocation(); + BlockFace blockFace = observer.getFacing().getOppositeFace(); + location.add(blockFace.getModX(), -1, blockFace.getModZ()); + if (location.getY() >= 0) { + Block b = location.getBlock(); + if (b.getType() == Material.DROPPER || b.getType() == Material.DISPENSER) { + blockList.add(b); + } + } + } } private void calculateRedstoneLamp(Block block) { @@ -161,21 +185,79 @@ public class ObserverTracer { if (block.getType() == Material.REDSTONE_LAMP) { return true; } + if (block.getType() == Material.BELL) { + return true; + } return blockData instanceof Door || blockData instanceof Gate || blockData instanceof NoteBlock || blockData instanceof CraftPoweredRail - || blockData instanceof TrapDoor; + || blockData instanceof TrapDoor + || blockData instanceof GlassPane; } private void calculateSpecial(Block block) { + BlockData blockData = block.getBlockData(); + Location blockLocation = block.getLocation(); + if (blockData instanceof TrapDoor) { + TrapDoor trapDoor = (TrapDoor) blockData; + fence(trapDoor.getFacing().getOppositeFace(), blockLocation); + } + if (blockData instanceof Door) { + Door door = (Door) blockData; + fence(door.getFacing().getOppositeFace(), blockLocation); + fence(doorHinge(door.getFacing(), door.getHinge()), blockLocation); + } + calculateSimple(block); + } + + private void fence(BlockFace current, Location location) { + Block b = location.clone().add(current.getModX(), current.getModY(), current.getModZ()).getBlock(); + if (b.getBlockData() instanceof Fence || b.getBlockData() instanceof GlassPane) { + blockList.add(b); + } + } + + private BlockFace doorHinge(BlockFace blockFace, Door.Hinge hinge) { + switch (blockFace) { + case WEST: + if (hinge == Door.Hinge.RIGHT) { + return BlockFace.NORTH; + } else { + return BlockFace.SOUTH; + } + case SOUTH: + if (hinge == Door.Hinge.RIGHT) { + return BlockFace.WEST; + } else { + return BlockFace.EAST; + } + case EAST: + if (hinge == Door.Hinge.RIGHT) { + return BlockFace.SOUTH; + } else { + return BlockFace.NORTH; + } + case NORTH: + if (hinge == Door.Hinge.RIGHT) { + return BlockFace.EAST; + } else { + return BlockFace.WEST; + } + default: + throw new SecurityException(); + } + } + + private void calculateSimple(Block block) { + Location blockLocation = block.getLocation(); for (BlockFace blockFace : ALLOWED) { - Location location = block.getLocation().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ()); + Location location = blockLocation.clone().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ()); Block b = location.getBlock(); if (b.getType() == Material.OBSERVER) { - Observer blockData = (Observer) b.getBlockData(); - if (blockData.getFacing() == blockFace.getOppositeFace()) { + Observer current = (Observer) b.getBlockData(); + if (current.getFacing() == blockFace.getOppositeFace()) { blockList.add(b); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java index 348da1c0..de1cf3a1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java @@ -44,4 +44,14 @@ public class ObserverTracerCommand extends SWCommand { BauSystem.MESSAGE.send("OBSERVER_DELETE", p); } + @Register(value = "retrace") + public void retrace(Player p) { + if (ObserverTracerListener.observerTracerMap.containsKey(p)) { + BauSystem.MESSAGE.send("OBSERVER_RETRACE_NO-TRACE", p); + return; + } + ObserverTracerListener.observerTracerMap.get(p).trace(); + BauSystem.MESSAGE.send("OBSERVER_RETRACE_DONE", p); + } + }