SteamWar/BauSystem2.0
Archiviert
12
0

Update Laufbau
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-02-03 18:21:25 +01:00
Ursprung 4ea99f93e4
Commit d7062b07a3

Datei anzeigen

@ -22,28 +22,20 @@ package de.steamwar.bausystem.features.slaves.laufbau;
import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.features.tracer.TNTPosition;
import de.steamwar.bausystem.features.tracer.show.StoredRecords; import de.steamwar.bausystem.features.tracer.show.StoredRecords;
import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.FlatteningWrapper;
import lombok.EqualsAndHashCode; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer;
public class Laufbau { public class Laufbau {
private Set<TNTPosition> tntPositions = new HashSet<>(); private Set<TNTPosition> tntPositions = new HashSet<>();
private Map<Point, Type> laufMap = new HashMap<>(); private Set<Cuboid> cuboidList = new HashSet<>();
private World world; private World world;
private Location pos1; private Location pos1;
@ -64,10 +56,10 @@ public class Laufbau {
if (FlatteningWrapper.impl.inWater(world, tntPosition.getLocation())) { if (FlatteningWrapper.impl.inWater(world, tntPosition.getLocation())) {
return; return;
} }
if (inRegionExpanded(tntPosition.getLocation().toLocation(world))) { if (inRegion(tntPosition.getLocation().toLocation(world), 1)) {
tntPositions.add(tntPosition); tntPositions.add(tntPosition);
} }
if (tntPosition.getPreviousLocation() != null && inRegionExpanded(tntPosition.getPreviousLocation().toLocation(world))) { if (tntPosition.getPreviousLocation() != null && inRegion(tntPosition.getPreviousLocation().toLocation(world), 1)) {
tntPositions.add(tntPosition); tntPositions.add(tntPosition);
} }
}); });
@ -75,88 +67,67 @@ public class Laufbau {
}); });
for (TNTPosition tntPosition : tntPositions) { for (TNTPosition tntPosition : tntPositions) {
Vector current = tntPosition.getLocation(); Vector location = tntPosition.getLocation();
Vector previousLocation = tntPosition.getPreviousLocation();
boolean xPositive = current.getX() - (int) current.getX() > 0; if (previousLocation == null) {
boolean yPositive = current.getY() - (int) current.getY() >= 0.5; cuboidList.add(new Cuboid(location.getX() - 0.49, location.getY() - 0.49, location.getZ() - 0.49, 0.98, 0.98, 0.98));
boolean zPositive = current.getZ() - (int) current.getZ() > 0; } else {
cuboidList.add(new Cuboid(previousLocation.getX() - 0.49, previousLocation.getY() - 0.49, previousLocation.getZ() - 0.49, 0.98, location.getY() + 0.49, 0.98));
UnaryTriConsumer<Integer> coordinateConsumer = (x, y, z) -> { Vector movement = location.clone().subtract(previousLocation);
Point point = new Point(x, y + (yPositive ? 1 : 0), z); if (Math.abs(movement.getX()) > Math.abs(movement.getZ())) {
if (inRegion(point)) laufMap.put(point, Type.FULL); cuboidList.add(new Cuboid(previousLocation.getX() - 0.49, location.getY() - 0.49, previousLocation.getZ() - 0.49, location.getX() + 0.49, 0.98, 0.98));
point = new Point(x, y + (yPositive ? 0 : 1), z); cuboidList.add(new Cuboid(location.getX() - 0.49, location.getY() - 0.49, previousLocation.getZ() - 0.49, 0.98, 0.98, location.getZ() + 0.49));
if (inRegion(point)) laufMap.putIfAbsent(point, (yPositive ? Type.HALF_TOP : Type.HALF_BOTTOM)); } else {
}; cuboidList.add(new Cuboid(previousLocation.getX() - 0.49, location.getY() - 0.49, previousLocation.getZ() - 0.49, 0.98, 0.98, location.getZ() + 0.49));
update(current, xPositive, zPositive, coordinateConsumer); cuboidList.add(new Cuboid(location.getX() - 0.49, location.getY() - 0.49, previousLocation.getZ() - 0.49, location.getX() + 0.49, 0.98, 0.98));
}
if (tntPosition.getPreviousLocation() != null) { // TODO: Add interpolated cuboids'
boolean previousXPositive = tntPosition.getPreviousLocation().getX() - (int) tntPosition.getPreviousLocation().getX() > 0;
boolean previousZPositive = tntPosition.getPreviousLocation().getZ() - (int) tntPosition.getPreviousLocation().getZ() > 0;
System.out.println("- empty");
System.out.println(tntPosition.getPreviousLocation());
interpolate(tntPosition.getPreviousLocation().getY(), tntPosition.getLocation().getY(), y -> {
Vector vector = new Vector(tntPosition.getPreviousLocation().getX(), y, tntPosition.getPreviousLocation().getZ());
System.out.println(vector);
update(vector, previousXPositive, previousZPositive, coordinateConsumer);
});
System.out.println(tntPosition.getLocation());
// Vector movement = tntPosition.getLocation().clone().subtract(tntPosition.getPreviousLocation());
} }
} }
System.out.println(cuboidList);
System.out.println(cuboidList.size());
/*
BlockData fullBlock = Material.STONE.createBlockData(); BlockData fullBlock = Material.STONE.createBlockData();
Slab topBlock = (Slab) Material.STONE_SLAB.createBlockData(); Slab topBlock = (Slab) Material.STONE_SLAB.createBlockData();
Slab bottomBlock = (Slab) Material.STONE_SLAB.createBlockData(); Slab bottomBlock = (Slab) Material.STONE_SLAB.createBlockData();
topBlock.setType(Slab.Type.TOP); topBlock.setType(Slab.Type.TOP);
bottomBlock.setType(Slab.Type.BOTTOM); bottomBlock.setType(Slab.Type.BOTTOM);
Bukkit.getOnlinePlayers().forEach(player -> {
laufMap.forEach((point, type) -> { for (int x = this.pos1.getBlockX(); x <= this.pos2.getBlockX(); x++) {
for (int y = this.pos1.getBlockY(); y <= this.pos2.getBlockY(); y++) {
for (int z = this.pos1.getBlockZ(); z <= this.pos2.getBlockZ(); z++) {
Point point = new Point(x, y, z);
Type type = laufMap.getOrDefault(point, Type.EMPTY);
if (type == Type.FULL) continue;
Block block = world.getBlockAt(x, y, z);
if (!block.getType().isAir()) continue;
if (type == Type.HALF_TOP) { if (type == Type.HALF_TOP) {
player.sendBlockChange(point.toVector().toLocation(world), topBlock); block.setBlockData(bottomBlock);
} else if (type == Type.HALF_BOTTOM) { } else if (type == Type.HALF_BOTTOM) {
player.sendBlockChange(point.toVector().toLocation(world), bottomBlock); block.setBlockData(topBlock);
} else if (type == Type.FULL) {
player.sendBlockChange(point.toVector().toLocation(world), fullBlock);
}
});
});
System.out.println(laufMap);
}
private void update(Vector current, boolean xPositive, boolean zPositive, UnaryTriConsumer<Integer> coordinateConsumer) {
coordinateConsumer.accept((int) current.getX(), (int) current.getY(), (int) current.getZ());
coordinateConsumer.accept((int) current.getX() + (xPositive ? 1 : -1), (int) current.getY(), (int) current.getZ());
coordinateConsumer.accept((int) current.getX(), (int) current.getY(), (int) current.getZ() + (zPositive ? 1 : -1));
coordinateConsumer.accept((int) current.getX() + (xPositive ? 1 : -1), (int) current.getY(), (int) current.getZ() + (zPositive ? 1 : -1));
}
private void interpolate(double from, double to, Consumer<Double> integerConsumer) {
if (from > to) {
for (double i = to; i <= from + 0.1; i += 0.1) {
integerConsumer.accept(i);
}
} else { } else {
for (double i = from; i <= to + 0.1; i += 0.1) { block.setBlockData(fullBlock);
integerConsumer.accept(i);
} }
} }
} }
}
*/
// System.out.println(laufMap);
}
private boolean inRegion(Location location) { private boolean inRegion(Location location, int expansion) {
return inRegion(location.toVector()); return inRegion(location.toVector(), expansion);
} }
private boolean inRegion(Point point) { private boolean inRegion(Vector location, int expansion) {
return inRegion(point.toVector()); if (location.getBlockX() >= pos1.getBlockX() - expansion) {
} if (location.getBlockY() >= pos1.getBlockY() - expansion) {
if (location.getBlockZ() >= pos1.getBlockZ() - expansion) {
private boolean inRegion(Vector location) { if (location.getBlockX() <= pos2.getBlockX() + expansion) {
if (location.getBlockX() >= pos1.getBlockX()) { if (location.getBlockY() <= pos2.getBlockY() + expansion) {
if (location.getBlockY() >= pos1.getBlockY()) { if (location.getBlockZ() <= pos2.getBlockZ() + expansion) {
if (location.getBlockZ() >= pos1.getBlockZ()) {
if (location.getBlockX() <= pos2.getBlockX()) {
if (location.getBlockY() <= pos2.getBlockY()) {
if (location.getBlockZ() <= pos2.getBlockZ()) {
return true; return true;
} }
} }
@ -167,55 +138,18 @@ public class Laufbau {
return false; return false;
} }
private boolean inRegionExpanded(Location location) { @Data
return inRegionExpanded(location.toVector()); @AllArgsConstructor
} private static class Cuboid {
private double x;
private double y;
private double z;
private double dx;
private double dy;
private double dz;
private boolean inRegionExpanded(Vector location) { private boolean inCuboid(Vector vector) {
if (location.getBlockX() > pos1.getBlockX() - 1) {
if (location.getBlockY() > pos1.getBlockY() - 1) {
if (location.getBlockZ() > pos1.getBlockZ() - 1) {
if (location.getBlockX() < pos2.getBlockX() + 1) {
if (location.getBlockY() < pos2.getBlockY() + 1) {
if (location.getBlockZ() < pos2.getBlockZ() + 1) {
return true;
}
}
}
}
}
}
return false; return false;
} }
private enum Type {
FULL,
HALF_BOTTOM,
HALF_TOP,
EMPTY
}
@Getter
@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
private class Point {
private final int x;
private final int y;
private final int z;
public Point(Vector vector) {
this.x = vector.getBlockX();
this.y = vector.getBlockY();
this.z = vector.getBlockZ();
}
public Vector toVector() {
return new Vector(x, y, z);
}
}
private interface UnaryTriConsumer<T> {
void accept(T first, T second, T third);
} }
} }