SteamWar/BauSystem2.0
Archiviert
12
0

Push current state
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-08-31 21:30:34 +02:00
Ursprung e42e123aaa
Commit 02c68a8b0b
6 geänderte Dateien mit 67 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -28,6 +28,9 @@ import java.util.List;
public class AxisMovementLimiter {
private double x;
private double y;
private double z;
private Axis axis;
private double movement;
@ -39,6 +42,9 @@ public class AxisMovementLimiter {
private double maxZ;
public AxisMovementLimiter(double x, double y, double z, Axis axis, double movement) {
this.x = x;
this.y = y;
this.z = z;
this.axis = axis;
this.movement = movement;
@ -75,6 +81,7 @@ public class AxisMovementLimiter {
}
break;
}
System.out.println(axis + " " + minX + " -> " + maxX + " " + minY + " -> " + maxY + " " + minZ + " -> " + maxZ);
}
private List<Pos> possibleCollisions() {
@ -98,6 +105,8 @@ public class AxisMovementLimiter {
// TODO: This can be optimized by optimizing the x,y,z loop layout
public double run() {
if (movement == 0.0) return 0.0;
BoundingBox movementBoundingBox = new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
List<Pos> poss = possibleCollisions();
@ -151,13 +160,14 @@ public class AxisMovementLimiter {
if (collision == null) {
return movement;
} else {
System.out.println(axis + " " + movement + " " + collision);
switch (axis) {
case X:
return movement + (collision - minX);
return x - collision;
case Y:
return movement + (collision - minY);
return y - collision;
case Z:
return movement + (collision - minZ);
return z - collision;
default:
throw new IllegalStateException("Unexpected value: " + axis);
}

Datei anzeigen

@ -65,14 +65,12 @@ public class Explosion {
private final double y;
private final double z;
private final List<TNT> entities;
public Explosion(TNT tnt, double x, double y, double z, List<TNT> entities) {
public Explosion(TNT tnt, double x, double y, double z) {
this.tnt = tnt;
this.x = x;
this.y = y;
this.z = z;
this.entities = entities;
}
public void calculate() {
@ -120,7 +118,7 @@ public class Explosion {
int t = floor(z - q - 1.0D);
int u = floor(z + q + 1.0D);
for (TNT currentTNT : entities) {
for (TNT currentTNT : Simulator19.tntList) {
if (currentTNT == tnt) continue;
if (!(currentTNT.getX() >= k && currentTNT.getY() >= r && currentTNT.getZ() >= t && currentTNT.getX() <= l && currentTNT.getY() <= s && currentTNT.getZ() <= u)) {
continue;

Datei anzeigen

@ -26,6 +26,7 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import org.bukkit.util.VoxelShape;
import java.util.*;
@ -51,6 +52,7 @@ public class Simulator19 implements Simulator {
private static long accessed = 0;
private static long cacheMisses = 0;
private static long aired = 0;
static final List<TNT> tntList = new ArrayList<>();
private static final Set<Pos> AIR_BLOCKS = new HashSet<>();
private static final Map<Pos, Material> BLOCK_TYPES_MAP = new HashMap<>();
private static final Map<Pos, BlockData> BLOCK_DATA_MAP = new HashMap<>();
@ -59,7 +61,6 @@ public class Simulator19 implements Simulator {
@Override
public synchronized PreviewRecord run(Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate) {
PreviewRecord previewRecord = new PreviewRecord();
List<TNT> tntList = new ArrayList<>();
int currentTick = 0;
long time = System.currentTimeMillis();
@ -73,7 +74,7 @@ public class Simulator19 implements Simulator {
pairs.forEach(pair -> {
if (pair.getValue() > 0) {
hasSomeLeft.set(true);
TNT tnt = new TNT(pair.getKey().location.getX(), pair.getKey().location.getY(), pair.getKey().location.getZ());
TNT tnt = new TNT(pair.getKey().location.getX() - 0.49, pair.getKey().location.getY(), pair.getKey().location.getZ() - 0.49);
if (!pair.getKey().xVelocity) tnt.setVx(0.0);
if (!pair.getKey().yVelocity) tnt.setVy(0.0);
if (!pair.getKey().zVelocity) tnt.setVz(0.0);
@ -96,6 +97,8 @@ public class Simulator19 implements Simulator {
}
tntList.removeAll(remove);
}
System.out.println(AIR_BLOCKS);
AIR_BLOCKS.forEach(pos -> previewRecord.addAir(new Vector(pos.x, pos.y, pos.z)));
System.out.println("Time: " + (System.currentTimeMillis() - time) + "ms " + cacheMisses + "/" + accessed + "/" + aired);
AIR_BLOCKS.clear();
@ -142,10 +145,10 @@ public class Simulator19 implements Simulator {
public static void clearBlock(Pos pos) {
aired++;
AIR_BLOCKS.add(pos);
BLOCK_DATA_MAP.put(pos, AIR_BLOCK_DATA);
BlockData blockData = BLOCK_DATA_MAP.put(pos, AIR_BLOCK_DATA);
}
public static void clearBlocks(Set<Pos> pos) {
public static void clearBlocks(Set<Pos> poss) { // TODO: Optimize
poss.forEach(Simulator19::clearBlock);
}
}

Datei anzeigen

@ -82,7 +82,7 @@ public class TNT {
this.fuse--;
if (this.fuse <= 0) {
Explosion explosion = new Explosion(this, x, y + 0.98 * 0.0625, z, new ArrayList<>());
Explosion explosion = new Explosion(this, x, y + 0.98 * 0.0625, z);
explosion.calculate();
return true;
}
@ -165,16 +165,16 @@ public class TNT {
return movement;
}
double mY = new OptimizedAxisMovementLimiter(x, y, z, Axis.Y, movement.getY()).run();
double mY = new AxisMovementLimiter(x, y, z, Axis.Y, movement.getY()).run();
boolean bl = Math.abs(movement.getX()) < Math.abs(movement.getZ());
if (bl) {
double mZ = new OptimizedAxisMovementLimiter(x, y + mY, z, Axis.Z, movement.getZ()).run();
double mX = new OptimizedAxisMovementLimiter(x, y + mY, z + mZ, Axis.X, movement.getX()).run();
double mZ = new AxisMovementLimiter(x, y + mY, z, Axis.Z, movement.getZ()).run();
double mX = new AxisMovementLimiter(x, y + mY, z + mZ, Axis.X, movement.getX()).run();
return new Vector(mX, mY, mZ);
} else {
double mX = new OptimizedAxisMovementLimiter(x, y + mY, z, Axis.X, movement.getX()).run();
double mZ = new OptimizedAxisMovementLimiter(x + mX, y + mY, z, Axis.Z, movement.getZ()).run();
double mX = new AxisMovementLimiter(x, y + mY, z, Axis.X, movement.getX()).run();
double mZ = new AxisMovementLimiter(x + mX, y + mY, z, Axis.Z, movement.getZ()).run();
return new Vector(mX, mY, mZ);
}
}

Datei anzeigen

@ -36,6 +36,7 @@ import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@ -98,10 +99,21 @@ public class TNTSimulatorListener implements Listener {
SimulatorStorage.getSimulatorNames().forEach(s -> {
SimulatorStorage.getSimulator(s)._hide(event.getPlayer());
});
PreviewRecord previewRecord = previewRecordMap.remove(event.getPlayer());
if (previewRecord != null) {
previewRecord.close(event.getPlayer());
}
}
private Map<Player, PreviewRecord> previewRecordMap = new HashMap<>();
@EventHandler
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
PreviewRecord current = previewRecordMap.remove(event.getPlayer());
if (current != null) {
current.close(event.getPlayer());
}
if (!ItemUtils.isItem(event.getOffHandItem(), "simulator")) {
return;
}
@ -121,6 +133,7 @@ public class TNTSimulatorListener implements Listener {
return;
}
previewRecord.add(event.getPlayer());
previewRecordMap.put(event.getPlayer(), previewRecord);
}
@EventHandler

Datei anzeigen

@ -21,22 +21,29 @@ package de.steamwar.bausystem.features.simulator.preview;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class PreviewRecord {
private static final BlockData AIR_BLOCK_DATA = Material.AIR.createBlockData();
private Set<Vector> vectorList = new HashSet<>();
private Set<Vector> destroyedBlocks = new HashSet<>();
private REntityServer rEntityServer;
public void add(double x, double y, double z) {
vectorList.add(new Vector(x, y, z));
vectorList.add(new Vector(x + 0.49, y, z + 0.49));
}
public void addAir(Vector destroyed) {
destroyedBlocks.add(destroyed);
}
public void add(Player player) {
@ -49,5 +56,19 @@ public class PreviewRecord {
});
}
rEntityServer.addPlayer(player);
destroyedBlocks.forEach(vector -> {
player.sendBlockChange(vector.toLocation(player.getWorld()), AIR_BLOCK_DATA);
});
}
public void close(Player player) {
rEntityServer.close();
rEntityServer = null;
destroyedBlocks.forEach(vector -> {
Location location = vector.toLocation(player.getWorld());
player.sendBlockChange(location, location.getBlock().getBlockData());
});
}
}