forked from SteamWar/SteamWar
Update SimulatorPreviewTNT
This commit is contained in:
+15
-4
@@ -81,14 +81,24 @@ 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 ||
|
||||
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;
|
||||
})
|
||||
.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;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean intersectsX(double x, double y, double z, BoundingBox boundingBox) {
|
||||
@@ -97,8 +107,9 @@ public class SimulatorPreviewAABB {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
+1
@@ -79,6 +79,7 @@ public class SimulatorPreviewData {
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
System.out.println("TICK");
|
||||
tnts.forEach(SimulatorPreviewTNT::tick);
|
||||
}
|
||||
|
||||
|
||||
+82
-36
@@ -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<CollisionData> 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<BoundingBox> 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<CollisionData> 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<BoundingBox> 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;
|
||||
|
||||
Reference in New Issue
Block a user