diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewAABB.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewAABB.java index 5b8ff937..d8b7c164 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewAABB.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewAABB.java @@ -81,24 +81,35 @@ public class SimulatorPreviewAABB { return voxelShape.getBoundingBoxes() .stream() .filter(boundingBox -> { + System.out.println(boundingBox); return minX - (x + boundingBox.getMaxX()) < -1.0E-7 && - maxX - (x + boundingBox.getMinX()) > 1.0E-7 && + maxX - (x + boundingBox.getMinX()) > 1.0E-7 || minY - (y + boundingBox.getMaxY()) < -1.0E-7 && - maxY - (y + boundingBox.getMinY()) > 1.0E-7 && + maxY - (y + boundingBox.getMinY()) > 1.0E-7 || minZ - (z + boundingBox.getMaxZ()) < -1.0E-7 && - maxZ - (z + boundingBox.getMinZ()) > 1.0E-7; + maxZ - (z + boundingBox.getMinZ()) > 1.0E-7; }) .collect(Collectors.toList()); } + public boolean intersects(double x, double y, double z, BoundingBox boundingBox) { + return minX - (x + boundingBox.getMaxX()) < -1.0E-7 && + maxX - (x + boundingBox.getMinX()) > 1.0E-7 && + minY - (y + boundingBox.getMaxY()) < -1.0E-7 && + maxY - (y + boundingBox.getMinY()) > 1.0E-7 && + minZ - (z + boundingBox.getMaxZ()) < -1.0E-7 && + maxZ - (z + boundingBox.getMinZ()) > 1.0E-7; + } + public boolean intersectsX(double x, double y, double z, BoundingBox boundingBox) { return minX - (x + boundingBox.getMaxX()) < -1.0E-7 && maxX - (x + boundingBox.getMinX()) > 1.0E-7; } public boolean intersectsY(int x, int y, int z, BoundingBox boundingBox) { - return minY - (y + boundingBox.getMaxY()) < -1.0E-7 && - maxY - (y + boundingBox.getMinY()) > 1.0E-7; + return (minY < y + boundingBox.getMinY() && maxY > y + boundingBox.getMinY()) || + (minY < y + boundingBox.getMaxY() && maxY > y + boundingBox.getMaxY()) || + (minY > y + boundingBox.getMinY() && maxY < y + boundingBox.getMaxY()); } public boolean intersectsZ(double x, double y, double z, BoundingBox boundingBox) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewData.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewData.java index 9e5ae5d0..42fc7745 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewData.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewData.java @@ -79,6 +79,7 @@ public class SimulatorPreviewData { } public void tick() { + System.out.println("TICK"); tnts.forEach(SimulatorPreviewTNT::tick); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewTNT.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewTNT.java index 72d2df61..a9f7b6ed 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewTNT.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/SimulatorPreviewTNT.java @@ -20,9 +20,11 @@ package de.steamwar.bausystem.features.simulator.preview; import lombok.RequiredArgsConstructor; +import org.bukkit.Axis; import org.bukkit.util.BoundingBox; import org.bukkit.util.Vector; import org.bukkit.util.VoxelShape; +import yapion.hierarchy.output.AbstractOutput; import java.util.ArrayList; import java.util.List; @@ -30,6 +32,7 @@ import java.util.Random; public class SimulatorPreviewTNT { + private static final double size = 0.98; private static final Random random = new Random(); private final SimulatorPreviewData data; @@ -132,31 +135,31 @@ public class SimulatorPreviewTNT { collide.z = 0; return; } - SimulatorPreviewAABB box = new SimulatorPreviewAABB(x, y, z, x + 0.98, y + 0.98, z + 0.98); - SimulatorPreviewAABB initialCollisionBox = box.copy(); - initialCollisionBox.expandTowards(vx, vy, vz); - System.out.println(vy); + SimulatorPreviewAABB box = new SimulatorPreviewAABB(x, y, z, x + size, y + size, z + size); + // SimulatorPreviewAABB initialCollisionBox = box.copy(); + // initialCollisionBox.expandTowards(vx, vy, vz); + // System.out.println(vy + " " + initialCollisionBox); - List collisionDataList = new ArrayList<>(); - for (int x = floor(initialCollisionBox.minX - 1.0E-7) - 1; x < floor(initialCollisionBox.maxX + 1.0E-7) + 1; x++) { - for (int y = floor(initialCollisionBox.minY - 1.0E-7) - 1; y < floor(initialCollisionBox.maxY + 1.0E-7) + 1; y++) { - for (int z = floor(initialCollisionBox.minZ - 1.0E-7) - 1; z < floor(initialCollisionBox.maxZ + 1.0E-7) + 1; z++) { - System.out.println(x + " " + y + " " + z); - VoxelShape shape = data.getBlockShape(x, y, z); - if (shape == null) continue; - List collisionBoxes = initialCollisionBox.intersects(x, y, z, shape); - if (collisionBoxes.isEmpty()) continue; - collisionDataList.add(new CollisionData(x, y, z, collisionBoxes)); - } - } - } - if (collisionDataList.isEmpty()) { - System.out.println("No collision found"); - collide.x = vx; - collide.y = vy; - collide.z = vz; - return; - } + // List collisionDataList = new ArrayList<>(); + // for (int x = floor(initialCollisionBox.minX - 1.0E-7) - 1; x < floor(initialCollisionBox.maxX + 1.0E-7) + 1; x++) { + // for (int y = floor(initialCollisionBox.minY - 1.0E-7) - 1; y < floor(initialCollisionBox.maxY + 1.0E-7) + 1; y++) { + // for (int z = floor(initialCollisionBox.minZ - 1.0E-7) - 1; z < floor(initialCollisionBox.maxZ + 1.0E-7) + 1; z++) { + // VoxelShape shape = data.getBlockShape(x, y, z); + // if (shape == null) continue; + // List collisionBoxes = initialCollisionBox.intersects(x, y, z, shape); + // System.out.println(x + " " + y + " " + z + " " + collisionBoxes); + // if (collisionBoxes.isEmpty()) continue; + // collisionDataList.add(new CollisionData(x, y, z, collisionBoxes)); + // } + // } + // } + // if (collisionDataList.isEmpty()) { + // System.out.println("No collision found"); + // collide.x = vx; + // collide.y = vy; + // collide.z = vz; + // return; + // } double vx = this.vx; double vy = this.vy; @@ -165,31 +168,23 @@ public class SimulatorPreviewTNT { System.out.println(vx + " " + vy + " " + vz); if (vy != 0) { - for (CollisionData collisionData : collisionDataList) { - vy = collideY(box, collisionData, vy); - } + vy = iterateBlocks(box.copy(), Axis.Y, vy); if (vy != 0) box.add(0, vy, 0); } boolean xSmaller = Math.abs(vx) < Math.abs(vz); if (xSmaller && vz != 0) { - for (CollisionData collisionData : collisionDataList) { - vz = collideZ(box, collisionData, vz); - } + vz = iterateBlocks(box.copy(), Axis.Z, vz); if (vz != 0) box.add(0, 0, vz); } if (vx != 0) { - for (CollisionData collisionData : collisionDataList) { - vx = collideX(box, collisionData, vx); - } + vz = iterateBlocks(box.copy(), Axis.X, vx); if (vx != 0) box.add(vx, 0, 0); } if (!xSmaller && vz != 0) { - for (CollisionData collisionData : collisionDataList) { - vz = collideZ(box, collisionData, vz); - } + vz = iterateBlocks(box.copy(), Axis.Z, vz); if (vz != 0) box.add(0, 0, vz); } @@ -200,6 +195,57 @@ public class SimulatorPreviewTNT { collide.z = vz; } + private double iterateBlocks(SimulatorPreviewAABB box, Axis axis, double v) { + switch (axis) { + case X -> box.expandTowards(v, 0, 0); + case Y -> box.expandTowards(0, v, 0); + case Z -> box.expandTowards(0, 0, v); + } + for (int x = floor(box.minX - 1.0E-7) - 1; x < floor(box.maxX + 1.0E-7) + 1; x++) { + for (int y = floor(box.minY - 1.0E-7) - 1; y < floor(box.maxY + 1.0E-7) + 1; y++) { + for (int z = floor(box.minZ - 1.0E-7) - 1; z < floor(box.maxZ + 1.0E-7) + 1; z++) { + VoxelShape shape = data.getBlockShape(x, y, z); + if (shape == null) continue; + for (BoundingBox other : shape.getBoundingBoxes()) { + switch (axis) { + case X -> { + if (box.intersects(x, y, z, other)) { + System.out.println(x + " " + y + " " + z); + if (x < 0) { + v = Math.max(v, x + other.getMaxX() - this.x); + } else { + v = Math.min(v, x + other.getMinX() - this.x - size); + } + } + } + case Y -> { + if (box.intersects(x, y, z, other)) { + System.out.println(x + " " + y + " " + z); + if (v < 0) { + v = Math.max(v, y + other.getMaxY() - this.y); + } else { + v = Math.min(v, y + other.getMinY() - this.y - size); + } + } + } + case Z -> { + if (box.intersects(x, y, z, other)) { + System.out.println(x + " " + y + " " + z); + if (z < 0) { + v = Math.max(v, z + other.getMaxZ() - this.z); + } else { + v = Math.min(v, z + other.getMinZ() - this.z - size); + } + } + } + } + } + } + } + } + return v; + } + public static int floor(double value) { int i = (int) value; return value < (double) i ? i - 1 : i;