SteamWar/BauSystem2.0
Archiviert
12
0

Fix ObserverTracer

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-06-26 12:49:32 +02:00
Ursprung 6668f829af
Commit 86036455ec

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.features.observer; package de.steamwar.bausystem.features.observer;
import de.steamwar.bausystem.region.Point;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Particle; import org.bukkit.Particle;
@ -39,7 +40,7 @@ public class ObserverTracer {
private Player player; private Player player;
private Block block; private Block block;
Set<Location> seen = new HashSet<>(); Set<Point> seen = new HashSet<>();
private List<Block> blockList = new ArrayList<>(); private List<Block> blockList = new ArrayList<>();
public ObserverTracer(Player player, Block block) { public ObserverTracer(Player player, Block block) {
@ -48,8 +49,9 @@ public class ObserverTracer {
} }
public void show() { public void show() {
for (Location l : seen) { for (Point p : seen) {
spawnParticle(player, l, l.getBlock()); Location location = p.toLocation(player);
spawnParticle(player, location, location.getBlock());
} }
} }
@ -64,13 +66,12 @@ public class ObserverTracer {
blockList.add(block); blockList.add(block);
while (!blockList.isEmpty()) { while (!blockList.isEmpty()) {
blockList.removeIf(b -> seen.contains(b.getLocation()));
if (blockList.isEmpty()) {
break;
}
Block b = blockList.remove(0); Block b = blockList.remove(0);
seen.add(b.getLocation()); Point point = Point.fromLocation(b.getLocation());
if (seen.contains(point)) {
continue;
}
seen.add(point);
spawnParticle(player, b.getLocation(), b); spawnParticle(player, b.getLocation(), b);
if (b.getType() == Material.OBSERVER) { if (b.getType() == Material.OBSERVER) {
@ -93,11 +94,9 @@ public class ObserverTracer {
} }
if (checkAllowed(b, blockData)) { if (checkAllowed(b, blockData)) {
calculateSpecial(b); calculateSpecial(b);
}
if (b.getType() == Material.OBSERVER) {
continue; continue;
} }
if (b.getType().isBlock() && b.getType().isSolid() && b.getType().isOccluding()) { if (b.getType().isBlock() && b.getType().isSolid() && b.getType().isOccluding()) {
calculateSolidBlock(b); calculateSolidBlock(b);
} }
@ -120,10 +119,12 @@ public class ObserverTracer {
Location location = block.getLocation().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ()); Location location = block.getLocation().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ());
Block b = location.getBlock(); Block b = location.getBlock();
if (blockFace == observer.getFacing().getOppositeFace() && !b.getType().isAir()) { if (blockFace == observer.getFacing().getOppositeFace() && !b.getType().isAir()) {
if (b.getType() == Material.OBSERVER) {
continue;
}
blockList.add(b); blockList.add(b);
Material material = b.getType(); if (checkMaterial(b)) {
if (material == Material.REDSTONE_LAMP || material == Material.DROPPER || material == Material.DISPENSER) { calculateSolidBlock(b);
calculateRedstoneLamp(b);
} }
continue; continue;
} }
@ -157,7 +158,7 @@ public class ObserverTracer {
} }
} }
private void calculateRedstoneLamp(Block block) { private void calculateSolidBlock(Block block) {
for (BlockFace blockFace : ALLOWED) { for (BlockFace blockFace : ALLOWED) {
Location location = block.getLocation().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ()); Location location = block.getLocation().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ());
Block b = location.getBlock(); Block b = location.getBlock();
@ -167,18 +168,20 @@ public class ObserverTracer {
} }
} }
private void calculateSolidBlock(Block block) { private boolean checkAllowed(Block block, BlockData blockData) {
for (BlockFace blockFace : ALLOWED) { if (checkMaterial(block)) return true;
Location location = block.getLocation().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ()); if (block.getType() == Material.BELL) {
Block b = location.getBlock(); return true;
BlockData blockData = b.getBlockData();
if (checkAllowed(b, blockData)) {
blockList.add(b);
}
}
} }
private boolean checkAllowed(Block block, BlockData blockData) { return blockData instanceof Door
|| blockData instanceof Gate
|| blockData instanceof CraftPoweredRail
|| blockData instanceof TrapDoor
|| blockData instanceof GlassPane;
}
private boolean checkMaterial(Block block) {
if (block.getType() == Material.DROPPER) { if (block.getType() == Material.DROPPER) {
return true; return true;
} }
@ -191,16 +194,10 @@ public class ObserverTracer {
if (block.getType() == Material.REDSTONE_LAMP) { if (block.getType() == Material.REDSTONE_LAMP) {
return true; return true;
} }
if (block.getType() == Material.BELL) { if (block.getType() == Material.NOTE_BLOCK) {
return true; return true;
} }
return false;
return blockData instanceof Door
|| blockData instanceof Gate
|| blockData instanceof NoteBlock
|| blockData instanceof CraftPoweredRail
|| blockData instanceof TrapDoor
|| blockData instanceof GlassPane;
} }
private void calculateSpecial(Block block) { private void calculateSpecial(Block block) {