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