This commit is contained in:
@ -23,7 +23,7 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
|
||||
import de.steamwar.bausystem.features.simulator.preview.SimulatorPreviewData;
|
||||
import de.steamwar.bausystem.features.simulator.preview.SimulatorPreviewCalculator;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
@ -31,6 +31,7 @@ import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import de.steamwar.linkage.MinVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -93,11 +94,16 @@ public class SimulatorCommand extends SWCommand {
|
||||
|
||||
@Register(value = "test")
|
||||
public void test(Player player) {
|
||||
SimulatorPreviewData data = new SimulatorPreviewData(null);
|
||||
data.spawnTNT(0, 120, 0);
|
||||
data.tick();
|
||||
data.tick();
|
||||
data.tick();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
SimulatorPreviewCalculator data = new SimulatorPreviewCalculator(null);
|
||||
data.spawnTNT(0, 166, 0);
|
||||
data.calculate(simulatorPreviewResult -> {
|
||||
simulatorPreviewResult.show(player);
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
simulatorPreviewResult.hide(player);
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ClassMapper(value = Simulator.class, local = true)
|
||||
|
||||
@ -65,33 +65,6 @@ public class SimulatorPreviewAABB {
|
||||
minZ += vz;
|
||||
}
|
||||
|
||||
public double sizeX() {
|
||||
return maxX - minX;
|
||||
}
|
||||
|
||||
public double sizeY() {
|
||||
return maxY - minY;
|
||||
}
|
||||
|
||||
public double sizeZ() {
|
||||
return maxZ - minZ;
|
||||
}
|
||||
|
||||
public List<BoundingBox> intersects(int x, int y, int z, VoxelShape voxelShape) {
|
||||
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 &&
|
||||
@ -100,20 +73,4 @@ public class SimulatorPreviewAABB {
|
||||
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.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) {
|
||||
return minZ - (z + boundingBox.getMaxZ()) < -1.0E-7 &&
|
||||
maxZ - (z + boundingBox.getMinZ()) > 1.0E-7;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.preview;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.tracer.TNTPoint;
|
||||
import de.steamwar.bausystem.features.tracer.Trace;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.Consumer;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.util.VoxelShape;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SimulatorPreviewCalculator {
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
public final Simulator simulator;
|
||||
public final List<SimulatorPreviewTNT> tnts = new ArrayList<>();
|
||||
|
||||
private int ticks = 0;
|
||||
private final Set<SimulatorPreviewPos> air = new HashSet<>();
|
||||
private final Map<SimulatorPreviewPos, BlockData> datas = new HashMap<>();
|
||||
private final Map<SimulatorPreviewPos, VoxelShape> shapes = new HashMap<>();
|
||||
|
||||
public BlockData getBlockData(int x, int y, int z) {
|
||||
SimulatorPreviewPos pos = new SimulatorPreviewPos(x, y, z);
|
||||
if (air.contains(pos)) return null;
|
||||
return datas.computeIfAbsent(pos, __ -> {
|
||||
BlockData blockData = WORLD.getBlockData(x, y, z);
|
||||
if (blockData.getMaterial().isAir()) {
|
||||
air.add(pos);
|
||||
return null;
|
||||
}
|
||||
return blockData;
|
||||
});
|
||||
}
|
||||
|
||||
public VoxelShape getBlockShape(int x, int y, int z) {
|
||||
SimulatorPreviewPos pos = new SimulatorPreviewPos(x, y, z);
|
||||
if (air.contains(pos)) return null;
|
||||
return shapes.computeIfAbsent(pos, __ -> {
|
||||
Block block = WORLD.getBlockAt(x, y, z);
|
||||
if (block.getType().isAir()) {
|
||||
air.add(pos);
|
||||
return null;
|
||||
}
|
||||
return block.getCollisionShape();
|
||||
});
|
||||
}
|
||||
|
||||
public void setAir(int x, int y, int z) {
|
||||
SimulatorPreviewPos pos = new SimulatorPreviewPos(x, y, z);
|
||||
air.add(pos);
|
||||
datas.remove(pos);
|
||||
shapes.remove(pos);
|
||||
}
|
||||
|
||||
public void spawnTNT(double x, double y, double z) {
|
||||
tnts.add(new SimulatorPreviewTNT(this, x, y, z));
|
||||
}
|
||||
|
||||
public void calculate(Consumer<SimulatorPreviewResult> result) {
|
||||
List<TNTPoint> tntPoints = new ArrayList<>();
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
|
||||
long time = System.currentTimeMillis();
|
||||
while (!tnts.isEmpty()) {
|
||||
if (System.currentTimeMillis() - time > 40) {
|
||||
return;
|
||||
}
|
||||
tick(tntPoints);
|
||||
}
|
||||
bukkitTask.cancel();
|
||||
System.out.println(tntPoints);
|
||||
result.accept(new SimulatorPreviewResult(new Trace(null, tntPoints), air));
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
private void tick(List<TNTPoint> tntPoints) {
|
||||
System.out.println("TICK");
|
||||
tnts.removeIf(simulatorPreviewTNT -> {
|
||||
tntPoints.add(new TNTPoint(0, false, false, true, false, false, ticks, simulatorPreviewTNT.fuse, new Location(WORLD, simulatorPreviewTNT.x + 0.49, simulatorPreviewTNT.y, simulatorPreviewTNT.z + 0.49), new Vector(simulatorPreviewTNT.vx, simulatorPreviewTNT.vy, simulatorPreviewTNT.vz), tntPoints));
|
||||
simulatorPreviewTNT.tick();
|
||||
if (!simulatorPreviewTNT.removed) return false;
|
||||
tntPoints.add(new TNTPoint(0, true, false, true, false, false, ticks, simulatorPreviewTNT.fuse, new Location(WORLD, simulatorPreviewTNT.x + 0.49, simulatorPreviewTNT.y, simulatorPreviewTNT.z + 0.49), new Vector(simulatorPreviewTNT.vx, simulatorPreviewTNT.vy, simulatorPreviewTNT.vz), tntPoints));
|
||||
return true;
|
||||
});
|
||||
ticks++;
|
||||
}
|
||||
}
|
||||
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.preview;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.VoxelShape;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SimulatorPreviewData {
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
public final Simulator simulator;
|
||||
public final List<SimulatorPreviewTNT> tnts = new ArrayList<>();
|
||||
|
||||
private final Set<Pos> AIR = new HashSet<>();
|
||||
private final Map<Pos, BlockData> datas = new HashMap<>();
|
||||
private final Map<Pos, VoxelShape> shapes = new HashMap<>();
|
||||
|
||||
public BlockData getBlockData(int x, int y, int z) {
|
||||
Pos pos = new Pos(x, y, z);
|
||||
if (AIR.contains(pos)) return null;
|
||||
return datas.computeIfAbsent(pos, __ -> {
|
||||
BlockData blockData = WORLD.getBlockData(x, y, z);
|
||||
if (blockData.getMaterial().isAir()) {
|
||||
AIR.add(pos);
|
||||
return null;
|
||||
}
|
||||
return blockData;
|
||||
});
|
||||
}
|
||||
|
||||
public VoxelShape getBlockShape(int x, int y, int z) {
|
||||
Pos pos = new Pos(x, y, z);
|
||||
if (AIR.contains(pos)) return null;
|
||||
return shapes.computeIfAbsent(pos, __ -> {
|
||||
Block block = WORLD.getBlockAt(x, y, z);
|
||||
if (block.getType().isAir()) {
|
||||
AIR.add(pos);
|
||||
return null;
|
||||
}
|
||||
return block.getCollisionShape();
|
||||
});
|
||||
}
|
||||
|
||||
public void setAir(int x, int y, int z) {
|
||||
Pos pos = new Pos(x, y, z);
|
||||
AIR.add(pos);
|
||||
datas.remove(pos);
|
||||
shapes.remove(pos);
|
||||
}
|
||||
|
||||
public void spawnTNT(double x, double y, double z) {
|
||||
tnts.add(new SimulatorPreviewTNT(this, x, y, z));
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
System.out.println("TICK");
|
||||
tnts.forEach(SimulatorPreviewTNT::tick);
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
private final class Pos {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.preview;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
final class SimulatorPreviewPos {
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int z;
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.preview;
|
||||
|
||||
import de.steamwar.bausystem.features.tracer.Trace;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.PlayerTraceShowData;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
public class SimulatorPreviewResult {
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
private static final BlockData AIR = Material.AIR.createBlockData();
|
||||
|
||||
private final Trace trace;
|
||||
private final Set<SimulatorPreviewPos> air;
|
||||
|
||||
public SimulatorPreviewResult(Trace trace, Set<SimulatorPreviewPos> air) {
|
||||
this.trace = trace;
|
||||
this.air = air;
|
||||
}
|
||||
|
||||
public void show(Player player) {
|
||||
trace.render(player, new PlayerTraceShowData(BundleFilter.DEFAULT));
|
||||
air.forEach(simulatorPreviewPos -> {
|
||||
player.sendBlockChange(new Location(WORLD, simulatorPreviewPos.x, simulatorPreviewPos.y, simulatorPreviewPos.z, 0, 0), AIR);
|
||||
});
|
||||
}
|
||||
|
||||
public void hide(Player player) {
|
||||
trace.hide(player);
|
||||
air.forEach(simulatorPreviewPos -> {
|
||||
player.sendBlockChange(new Location(WORLD, simulatorPreviewPos.x, simulatorPreviewPos.y, simulatorPreviewPos.z, 0, 0), WORLD.getBlockData(simulatorPreviewPos.x, simulatorPreviewPos.y, simulatorPreviewPos.z));
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -19,15 +19,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;
|
||||
import java.util.Random;
|
||||
|
||||
public class SimulatorPreviewTNT {
|
||||
@ -35,20 +31,21 @@ public class SimulatorPreviewTNT {
|
||||
private static final double size = 0.98;
|
||||
private static final Random random = new Random();
|
||||
|
||||
private final SimulatorPreviewData data;
|
||||
private final SimulatorPreviewCalculator data;
|
||||
private boolean gravity = true;
|
||||
private int fuse = 80;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private double vx;
|
||||
private double vy;
|
||||
private double vz;
|
||||
int fuse = 80;
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
double vx;
|
||||
double vy;
|
||||
double vz;
|
||||
|
||||
private SimulatorPreviewVec collide = new SimulatorPreviewVec();
|
||||
private boolean onGround;
|
||||
boolean removed = false;
|
||||
|
||||
public SimulatorPreviewTNT(SimulatorPreviewData data, double x, double y, double z) {
|
||||
public SimulatorPreviewTNT(SimulatorPreviewCalculator data, double x, double y, double z) {
|
||||
this.data = data;
|
||||
|
||||
this.x = x;
|
||||
@ -62,6 +59,8 @@ public class SimulatorPreviewTNT {
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
// TODO: Issue in movement still!
|
||||
// System.out.println(x + " " + y + " " + z);
|
||||
// Gravity
|
||||
if (gravity) {
|
||||
vy -= 0.04;
|
||||
@ -115,15 +114,15 @@ public class SimulatorPreviewTNT {
|
||||
if (xCollision) vx = 0;
|
||||
if (zCollision) vz = 0;
|
||||
}
|
||||
// vx = collide.x;
|
||||
vx = collide.x;
|
||||
vy = collide.y;
|
||||
// vz = collide.z;
|
||||
vz = collide.z;
|
||||
// TODO: Get Block -> updateEntityMovementAfterFallOn!
|
||||
// TODO: Get BlockSpeedFactor multiply
|
||||
}
|
||||
|
||||
public static boolean equal(double x, double y) {
|
||||
return Math.abs(y - x) < (double) 1.0E-5F;
|
||||
public static boolean equal(double first, double second) {
|
||||
return Math.abs(second - first) < (double) 1.0E-5F;
|
||||
}
|
||||
|
||||
public void collide() {
|
||||
@ -136,37 +135,11 @@ public class SimulatorPreviewTNT {
|
||||
return;
|
||||
}
|
||||
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++) {
|
||||
// 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;
|
||||
double vz = this.vz;
|
||||
|
||||
System.out.println(vx + " " + vy + " " + vz);
|
||||
|
||||
if (vy != 0) {
|
||||
vy = iterateBlocks(box.copy(), Axis.Y, vy);
|
||||
if (vy != 0) box.add(0, vy, 0);
|
||||
@ -179,7 +152,7 @@ public class SimulatorPreviewTNT {
|
||||
}
|
||||
|
||||
if (vx != 0) {
|
||||
vz = iterateBlocks(box.copy(), Axis.X, vx);
|
||||
vx = iterateBlocks(box.copy(), Axis.X, vx);
|
||||
if (vx != 0) box.add(vx, 0, 0);
|
||||
}
|
||||
|
||||
@ -188,8 +161,6 @@ public class SimulatorPreviewTNT {
|
||||
if (vz != 0) box.add(0, 0, vz);
|
||||
}
|
||||
|
||||
System.out.println(vx + " " + vy + " " + vz);
|
||||
|
||||
collide.x = vx;
|
||||
collide.y = vy;
|
||||
collide.z = vz;
|
||||
@ -201,6 +172,7 @@ public class SimulatorPreviewTNT {
|
||||
case Y -> box.expandTowards(0, v, 0);
|
||||
case Z -> box.expandTowards(0, 0, v);
|
||||
}
|
||||
boolean negative = v < 0;
|
||||
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++) {
|
||||
@ -210,8 +182,7 @@ public class SimulatorPreviewTNT {
|
||||
switch (axis) {
|
||||
case X -> {
|
||||
if (box.intersects(x, y, z, other)) {
|
||||
System.out.println(x + " " + y + " " + z);
|
||||
if (x < 0) {
|
||||
if (negative) {
|
||||
v = Math.max(v, x + other.getMaxX() - this.x);
|
||||
} else {
|
||||
v = Math.min(v, x + other.getMinX() - this.x - size);
|
||||
@ -220,8 +191,7 @@ public class SimulatorPreviewTNT {
|
||||
}
|
||||
case Y -> {
|
||||
if (box.intersects(x, y, z, other)) {
|
||||
System.out.println(x + " " + y + " " + z);
|
||||
if (v < 0) {
|
||||
if (negative) {
|
||||
v = Math.max(v, y + other.getMaxY() - this.y);
|
||||
} else {
|
||||
v = Math.min(v, y + other.getMinY() - this.y - size);
|
||||
@ -230,8 +200,7 @@ public class SimulatorPreviewTNT {
|
||||
}
|
||||
case Z -> {
|
||||
if (box.intersects(x, y, z, other)) {
|
||||
System.out.println(x + " " + y + " " + z);
|
||||
if (z < 0) {
|
||||
if (negative) {
|
||||
v = Math.max(v, z + other.getMaxZ() - this.z);
|
||||
} else {
|
||||
v = Math.min(v, z + other.getMinZ() - this.z - size);
|
||||
@ -251,73 +220,8 @@ public class SimulatorPreviewTNT {
|
||||
return value < (double) i ? i - 1 : i;
|
||||
}
|
||||
|
||||
public static double collideX(SimulatorPreviewAABB box, CollisionData collisionData, double vx) {
|
||||
if (vx < 0) {
|
||||
for (BoundingBox boundingBox : collisionData.collisions) {
|
||||
if (box.intersectsX(collisionData.x + vx, collisionData.y, collisionData.z, boundingBox)) {
|
||||
vx = Math.max(vx, boundingBox.getMaxX());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (BoundingBox boundingBox : collisionData.collisions) {
|
||||
if (box.intersectsX(collisionData.x + vx, collisionData.y, collisionData.z, boundingBox)) {
|
||||
vx = Math.min(vx, boundingBox.getMinX());
|
||||
}
|
||||
}
|
||||
vx -= box.sizeY();
|
||||
}
|
||||
return vx;
|
||||
}
|
||||
|
||||
public static double collideY(SimulatorPreviewAABB box, CollisionData collisionData, double vy) {
|
||||
double size = box.sizeY();
|
||||
box = box.copy();
|
||||
box.expandTowards(0, vy, 0);
|
||||
if (vy < 0) {
|
||||
for (BoundingBox boundingBox : collisionData.collisions) {
|
||||
if (box.intersectsY(collisionData.x, collisionData.y, collisionData.z, boundingBox)) {
|
||||
vy = Math.max(vy, boundingBox.getMaxY() + collisionData.y - box.minY - size);
|
||||
}
|
||||
}
|
||||
System.out.println("N: " + vy);
|
||||
} else {
|
||||
for (BoundingBox boundingBox : collisionData.collisions) {
|
||||
if (box.intersectsY(collisionData.x, collisionData.y, collisionData.z, boundingBox)) {
|
||||
vy = Math.min(vy, boundingBox.getMinY() + collisionData.y - box.minY - size);
|
||||
}
|
||||
}
|
||||
System.out.println("P: " + vy);
|
||||
}
|
||||
return vy;
|
||||
}
|
||||
|
||||
public static double collideZ(SimulatorPreviewAABB box, CollisionData collisionData, double vz) {
|
||||
if (vz < 0) {
|
||||
for (BoundingBox boundingBox : collisionData.collisions) {
|
||||
if (box.intersectsZ(collisionData.x, collisionData.y, collisionData.z + vz, boundingBox)) {
|
||||
vz = Math.max(vz, boundingBox.getMaxZ());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (BoundingBox boundingBox : collisionData.collisions) {
|
||||
if (box.intersectsZ(collisionData.x, collisionData.y, collisionData.z + vz, boundingBox)) {
|
||||
vz = Math.min(vz, boundingBox.getMinZ());
|
||||
}
|
||||
}
|
||||
vz -= box.sizeZ();
|
||||
}
|
||||
return vz;
|
||||
}
|
||||
|
||||
public void explode() {
|
||||
removed = true;
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private class CollisionData {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final List<BoundingBox> collisions;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,23 +25,18 @@ import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Recording of a tnt at a specific tick
|
||||
*/
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class TNTPoint{
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user