Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
e42e123aaa
Commit
02c68a8b0b
@ -28,6 +28,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AxisMovementLimiter {
|
public class AxisMovementLimiter {
|
||||||
|
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
private double z;
|
||||||
private Axis axis;
|
private Axis axis;
|
||||||
private double movement;
|
private double movement;
|
||||||
|
|
||||||
@ -39,6 +42,9 @@ public class AxisMovementLimiter {
|
|||||||
private double maxZ;
|
private double maxZ;
|
||||||
|
|
||||||
public AxisMovementLimiter(double x, double y, double z, Axis axis, double movement) {
|
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.axis = axis;
|
||||||
this.movement = movement;
|
this.movement = movement;
|
||||||
|
|
||||||
@ -75,6 +81,7 @@ public class AxisMovementLimiter {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
System.out.println(axis + " " + minX + " -> " + maxX + " " + minY + " -> " + maxY + " " + minZ + " -> " + maxZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Pos> possibleCollisions() {
|
private List<Pos> possibleCollisions() {
|
||||||
@ -98,6 +105,8 @@ public class AxisMovementLimiter {
|
|||||||
|
|
||||||
// TODO: This can be optimized by optimizing the x,y,z loop layout
|
// TODO: This can be optimized by optimizing the x,y,z loop layout
|
||||||
public double run() {
|
public double run() {
|
||||||
|
if (movement == 0.0) return 0.0;
|
||||||
|
|
||||||
BoundingBox movementBoundingBox = new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
|
BoundingBox movementBoundingBox = new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
|
||||||
List<Pos> poss = possibleCollisions();
|
List<Pos> poss = possibleCollisions();
|
||||||
|
|
||||||
@ -151,13 +160,14 @@ public class AxisMovementLimiter {
|
|||||||
if (collision == null) {
|
if (collision == null) {
|
||||||
return movement;
|
return movement;
|
||||||
} else {
|
} else {
|
||||||
|
System.out.println(axis + " " + movement + " " + collision);
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
case X:
|
case X:
|
||||||
return movement + (collision - minX);
|
return x - collision;
|
||||||
case Y:
|
case Y:
|
||||||
return movement + (collision - minY);
|
return y - collision;
|
||||||
case Z:
|
case Z:
|
||||||
return movement + (collision - minZ);
|
return z - collision;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + axis);
|
throw new IllegalStateException("Unexpected value: " + axis);
|
||||||
}
|
}
|
||||||
|
@ -65,14 +65,12 @@ public class Explosion {
|
|||||||
private final double y;
|
private final double y;
|
||||||
private final double z;
|
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.tnt = tnt;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.entities = entities;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculate() {
|
public void calculate() {
|
||||||
@ -120,7 +118,7 @@ public class Explosion {
|
|||||||
int t = floor(z - q - 1.0D);
|
int t = floor(z - q - 1.0D);
|
||||||
int u = 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 == tnt) continue;
|
||||||
if (!(currentTNT.getX() >= k && currentTNT.getY() >= r && currentTNT.getZ() >= t && currentTNT.getX() <= l && currentTNT.getY() <= s && currentTNT.getZ() <= u)) {
|
if (!(currentTNT.getX() >= k && currentTNT.getY() >= r && currentTNT.getZ() >= t && currentTNT.getX() <= l && currentTNT.getY() <= s && currentTNT.getZ() <= u)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -26,6 +26,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import org.bukkit.util.VoxelShape;
|
import org.bukkit.util.VoxelShape;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -51,6 +52,7 @@ public class Simulator19 implements Simulator {
|
|||||||
private static long accessed = 0;
|
private static long accessed = 0;
|
||||||
private static long cacheMisses = 0;
|
private static long cacheMisses = 0;
|
||||||
private static long aired = 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 Set<Pos> AIR_BLOCKS = new HashSet<>();
|
||||||
private static final Map<Pos, Material> BLOCK_TYPES_MAP = new HashMap<>();
|
private static final Map<Pos, Material> BLOCK_TYPES_MAP = new HashMap<>();
|
||||||
private static final Map<Pos, BlockData> BLOCK_DATA_MAP = new HashMap<>();
|
private static final Map<Pos, BlockData> BLOCK_DATA_MAP = new HashMap<>();
|
||||||
@ -59,7 +61,6 @@ public class Simulator19 implements Simulator {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized PreviewRecord run(Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate) {
|
public synchronized PreviewRecord run(Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate) {
|
||||||
PreviewRecord previewRecord = new PreviewRecord();
|
PreviewRecord previewRecord = new PreviewRecord();
|
||||||
List<TNT> tntList = new ArrayList<>();
|
|
||||||
int currentTick = 0;
|
int currentTick = 0;
|
||||||
|
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
@ -73,7 +74,7 @@ public class Simulator19 implements Simulator {
|
|||||||
pairs.forEach(pair -> {
|
pairs.forEach(pair -> {
|
||||||
if (pair.getValue() > 0) {
|
if (pair.getValue() > 0) {
|
||||||
hasSomeLeft.set(true);
|
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().xVelocity) tnt.setVx(0.0);
|
||||||
if (!pair.getKey().yVelocity) tnt.setVy(0.0);
|
if (!pair.getKey().yVelocity) tnt.setVy(0.0);
|
||||||
if (!pair.getKey().zVelocity) tnt.setVz(0.0);
|
if (!pair.getKey().zVelocity) tnt.setVz(0.0);
|
||||||
@ -96,6 +97,8 @@ public class Simulator19 implements Simulator {
|
|||||||
}
|
}
|
||||||
tntList.removeAll(remove);
|
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);
|
System.out.println("Time: " + (System.currentTimeMillis() - time) + "ms " + cacheMisses + "/" + accessed + "/" + aired);
|
||||||
|
|
||||||
AIR_BLOCKS.clear();
|
AIR_BLOCKS.clear();
|
||||||
@ -142,10 +145,10 @@ public class Simulator19 implements Simulator {
|
|||||||
public static void clearBlock(Pos pos) {
|
public static void clearBlock(Pos pos) {
|
||||||
aired++;
|
aired++;
|
||||||
AIR_BLOCKS.add(pos);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class TNT {
|
|||||||
|
|
||||||
this.fuse--;
|
this.fuse--;
|
||||||
if (this.fuse <= 0) {
|
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();
|
explosion.calculate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -165,16 +165,16 @@ public class TNT {
|
|||||||
return movement;
|
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());
|
boolean bl = Math.abs(movement.getX()) < Math.abs(movement.getZ());
|
||||||
if (bl) {
|
if (bl) {
|
||||||
double mZ = new OptimizedAxisMovementLimiter(x, y + mY, z, Axis.Z, movement.getZ()).run();
|
double mZ = new AxisMovementLimiter(x, y + mY, z, Axis.Z, movement.getZ()).run();
|
||||||
double mX = new OptimizedAxisMovementLimiter(x, y + mY, z + mZ, Axis.X, movement.getX()).run();
|
double mX = new AxisMovementLimiter(x, y + mY, z + mZ, Axis.X, movement.getX()).run();
|
||||||
return new Vector(mX, mY, mZ);
|
return new Vector(mX, mY, mZ);
|
||||||
} else {
|
} else {
|
||||||
double mX = new OptimizedAxisMovementLimiter(x, y + mY, z, Axis.X, movement.getX()).run();
|
double mX = new AxisMovementLimiter(x, y + mY, z, Axis.X, movement.getX()).run();
|
||||||
double mZ = new OptimizedAxisMovementLimiter(x + mX, y + mY, z, Axis.Z, movement.getZ()).run();
|
double mZ = new AxisMovementLimiter(x + mX, y + mY, z, Axis.Z, movement.getZ()).run();
|
||||||
return new Vector(mX, mY, mZ);
|
return new Vector(mX, mY, mZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import org.bukkit.event.player.*;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -98,10 +99,21 @@ public class TNTSimulatorListener implements Listener {
|
|||||||
SimulatorStorage.getSimulatorNames().forEach(s -> {
|
SimulatorStorage.getSimulatorNames().forEach(s -> {
|
||||||
SimulatorStorage.getSimulator(s)._hide(event.getPlayer());
|
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
|
@EventHandler
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
|
PreviewRecord current = previewRecordMap.remove(event.getPlayer());
|
||||||
|
if (current != null) {
|
||||||
|
current.close(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
if (!ItemUtils.isItem(event.getOffHandItem(), "simulator")) {
|
if (!ItemUtils.isItem(event.getOffHandItem(), "simulator")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -121,6 +133,7 @@ public class TNTSimulatorListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
previewRecord.add(event.getPlayer());
|
previewRecord.add(event.getPlayer());
|
||||||
|
previewRecordMap.put(event.getPlayer(), previewRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -21,22 +21,29 @@ package de.steamwar.bausystem.features.simulator.preview;
|
|||||||
|
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
import de.steamwar.entity.RFallingBlockEntity;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class PreviewRecord {
|
public class PreviewRecord {
|
||||||
|
|
||||||
|
private static final BlockData AIR_BLOCK_DATA = Material.AIR.createBlockData();
|
||||||
|
|
||||||
private Set<Vector> vectorList = new HashSet<>();
|
private Set<Vector> vectorList = new HashSet<>();
|
||||||
|
private Set<Vector> destroyedBlocks = new HashSet<>();
|
||||||
private REntityServer rEntityServer;
|
private REntityServer rEntityServer;
|
||||||
|
|
||||||
public void add(double x, double y, double z) {
|
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) {
|
public void add(Player player) {
|
||||||
@ -49,5 +56,19 @@ public class PreviewRecord {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
rEntityServer.addPlayer(player);
|
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());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren