forked from SteamWar/SteamWar
Update SimulatorPreviewTNT
This commit is contained in:
+16
-5
@@ -81,24 +81,35 @@ public class SimulatorPreviewAABB {
|
|||||||
return voxelShape.getBoundingBoxes()
|
return voxelShape.getBoundingBoxes()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(boundingBox -> {
|
.filter(boundingBox -> {
|
||||||
|
System.out.println(boundingBox);
|
||||||
return minX - (x + boundingBox.getMaxX()) < -1.0E-7 &&
|
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 &&
|
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 &&
|
minZ - (z + boundingBox.getMaxZ()) < -1.0E-7 &&
|
||||||
maxZ - (z + boundingBox.getMinZ()) > 1.0E-7;
|
maxZ - (z + boundingBox.getMinZ()) > 1.0E-7;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.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) {
|
public boolean intersectsX(double x, double y, double z, BoundingBox boundingBox) {
|
||||||
return minX - (x + boundingBox.getMaxX()) < -1.0E-7 &&
|
return minX - (x + boundingBox.getMaxX()) < -1.0E-7 &&
|
||||||
maxX - (x + boundingBox.getMinX()) > 1.0E-7;
|
maxX - (x + boundingBox.getMinX()) > 1.0E-7;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean intersectsY(int x, int y, int z, BoundingBox boundingBox) {
|
public boolean intersectsY(int x, int y, int z, BoundingBox boundingBox) {
|
||||||
return minY - (y + boundingBox.getMaxY()) < -1.0E-7 &&
|
return (minY < y + boundingBox.getMinY() && maxY > y + boundingBox.getMinY()) ||
|
||||||
maxY - (y + boundingBox.getMinY()) > 1.0E-7;
|
(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) {
|
public boolean intersectsZ(double x, double y, double z, BoundingBox boundingBox) {
|
||||||
|
|||||||
+1
@@ -79,6 +79,7 @@ public class SimulatorPreviewData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
System.out.println("TICK");
|
||||||
tnts.forEach(SimulatorPreviewTNT::tick);
|
tnts.forEach(SimulatorPreviewTNT::tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+82
-36
@@ -20,9 +20,11 @@
|
|||||||
package de.steamwar.bausystem.features.simulator.preview;
|
package de.steamwar.bausystem.features.simulator.preview;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.bukkit.Axis;
|
||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.bukkit.util.VoxelShape;
|
import org.bukkit.util.VoxelShape;
|
||||||
|
import yapion.hierarchy.output.AbstractOutput;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -30,6 +32,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class SimulatorPreviewTNT {
|
public class SimulatorPreviewTNT {
|
||||||
|
|
||||||
|
private static final double size = 0.98;
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
private final SimulatorPreviewData data;
|
private final SimulatorPreviewData data;
|
||||||
@@ -132,31 +135,31 @@ public class SimulatorPreviewTNT {
|
|||||||
collide.z = 0;
|
collide.z = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SimulatorPreviewAABB box = new SimulatorPreviewAABB(x, y, z, x + 0.98, y + 0.98, z + 0.98);
|
SimulatorPreviewAABB box = new SimulatorPreviewAABB(x, y, z, x + size, y + size, z + size);
|
||||||
SimulatorPreviewAABB initialCollisionBox = box.copy();
|
// SimulatorPreviewAABB initialCollisionBox = box.copy();
|
||||||
initialCollisionBox.expandTowards(vx, vy, vz);
|
// initialCollisionBox.expandTowards(vx, vy, vz);
|
||||||
System.out.println(vy);
|
// System.out.println(vy + " " + initialCollisionBox);
|
||||||
|
|
||||||
List<CollisionData> collisionDataList = new ArrayList<>();
|
// 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 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 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++) {
|
// 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);
|
||||||
VoxelShape shape = data.getBlockShape(x, y, z);
|
// if (shape == null) continue;
|
||||||
if (shape == null) continue;
|
// List<BoundingBox> collisionBoxes = initialCollisionBox.intersects(x, y, z, shape);
|
||||||
List<BoundingBox> collisionBoxes = initialCollisionBox.intersects(x, y, z, shape);
|
// System.out.println(x + " " + y + " " + z + " " + collisionBoxes);
|
||||||
if (collisionBoxes.isEmpty()) continue;
|
// if (collisionBoxes.isEmpty()) continue;
|
||||||
collisionDataList.add(new CollisionData(x, y, z, collisionBoxes));
|
// collisionDataList.add(new CollisionData(x, y, z, collisionBoxes));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (collisionDataList.isEmpty()) {
|
// if (collisionDataList.isEmpty()) {
|
||||||
System.out.println("No collision found");
|
// System.out.println("No collision found");
|
||||||
collide.x = vx;
|
// collide.x = vx;
|
||||||
collide.y = vy;
|
// collide.y = vy;
|
||||||
collide.z = vz;
|
// collide.z = vz;
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
double vx = this.vx;
|
double vx = this.vx;
|
||||||
double vy = this.vy;
|
double vy = this.vy;
|
||||||
@@ -165,31 +168,23 @@ public class SimulatorPreviewTNT {
|
|||||||
System.out.println(vx + " " + vy + " " + vz);
|
System.out.println(vx + " " + vy + " " + vz);
|
||||||
|
|
||||||
if (vy != 0) {
|
if (vy != 0) {
|
||||||
for (CollisionData collisionData : collisionDataList) {
|
vy = iterateBlocks(box.copy(), Axis.Y, vy);
|
||||||
vy = collideY(box, collisionData, vy);
|
|
||||||
}
|
|
||||||
if (vy != 0) box.add(0, vy, 0);
|
if (vy != 0) box.add(0, vy, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean xSmaller = Math.abs(vx) < Math.abs(vz);
|
boolean xSmaller = Math.abs(vx) < Math.abs(vz);
|
||||||
if (xSmaller && vz != 0) {
|
if (xSmaller && vz != 0) {
|
||||||
for (CollisionData collisionData : collisionDataList) {
|
vz = iterateBlocks(box.copy(), Axis.Z, vz);
|
||||||
vz = collideZ(box, collisionData, vz);
|
|
||||||
}
|
|
||||||
if (vz != 0) box.add(0, 0, vz);
|
if (vz != 0) box.add(0, 0, vz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vx != 0) {
|
if (vx != 0) {
|
||||||
for (CollisionData collisionData : collisionDataList) {
|
vz = iterateBlocks(box.copy(), Axis.X, vx);
|
||||||
vx = collideX(box, collisionData, vx);
|
|
||||||
}
|
|
||||||
if (vx != 0) box.add(vx, 0, 0);
|
if (vx != 0) box.add(vx, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!xSmaller && vz != 0) {
|
if (!xSmaller && vz != 0) {
|
||||||
for (CollisionData collisionData : collisionDataList) {
|
vz = iterateBlocks(box.copy(), Axis.Z, vz);
|
||||||
vz = collideZ(box, collisionData, vz);
|
|
||||||
}
|
|
||||||
if (vz != 0) box.add(0, 0, vz);
|
if (vz != 0) box.add(0, 0, vz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +195,57 @@ public class SimulatorPreviewTNT {
|
|||||||
collide.z = vz;
|
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) {
|
public static int floor(double value) {
|
||||||
int i = (int) value;
|
int i = (int) value;
|
||||||
return value < (double) i ? i - 1 : i;
|
return value < (double) i ? i - 1 : i;
|
||||||
|
|||||||
Reference in New Issue
Block a user