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