Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
e49724e593
Commit
7e2780f326
@ -195,7 +195,7 @@ public class Explosion {
|
|||||||
int oZ = sZ > dZ ? -1 : 1;
|
int oZ = sZ > dZ ? -1 : 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
Material material = simulatorData.getBlockType(floor(x), floor(y), floor(z));
|
Material material = simulatorData.getBlockType(floor(x), floor(y), floor(z));
|
||||||
if (material != Material.LAVA && material != Material.WATER && !material.isAir()) {
|
if (material != Material.LAVA && material != Material.WATER && material != Material.AIR) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +29,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -48,7 +45,7 @@ public class Simulator19 implements Simulator {
|
|||||||
private SimulatorData simulatorData = new SimulatorData();
|
private SimulatorData simulatorData = new SimulatorData();
|
||||||
private PreviewRecord previewRecord = new PreviewRecord();
|
private PreviewRecord previewRecord = new PreviewRecord();
|
||||||
private int currentTick = 0;
|
private int currentTick = 0;
|
||||||
private Map<TNT, Record.TNTRecord> recordMap = new HashMap<>();
|
private Map<TNT, Record.TNTRecord> recordMap = new IdentityHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -85,6 +82,7 @@ public class Simulator19 implements Simulator {
|
|||||||
|
|
||||||
List<TNT> remove = new ArrayList<>();
|
List<TNT> remove = new ArrayList<>();
|
||||||
for (TNT tnt : simulatorData.tntList) {
|
for (TNT tnt : simulatorData.tntList) {
|
||||||
|
// System.out.println("CALC: " + simulatorData.blockTypesMap.size() + "/" + simulatorData.blockDataMap.size() + "/" + simulatorData.collisionDataMap.size() + "/" + simulatorData.airBlocks.size() + " " + recordMap.size());
|
||||||
if (tnt.tick(simulatorData)) {
|
if (tnt.tick(simulatorData)) {
|
||||||
remove.add(tnt);
|
remove.add(tnt);
|
||||||
recordMap.remove(tnt).explode(new Vector(tnt.getX(), tnt.getY(), tnt.getZ()), new Vector(tnt.getVx(), tnt.getVy(), tnt.getVz()), tnt.getFuse());
|
recordMap.remove(tnt).explode(new Vector(tnt.getX(), tnt.getY(), tnt.getZ()), new Vector(tnt.getVx(), tnt.getVy(), tnt.getVz()), tnt.getFuse());
|
||||||
@ -95,9 +93,10 @@ public class Simulator19 implements Simulator {
|
|||||||
simulatorData.tntList.removeAll(remove);
|
simulatorData.tntList.removeAll(remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Time: " + (System.currentTimeMillis() - time) + "ms " + simulatorData.cacheMisses + "/" + simulatorData.accessed + "/" + simulatorData.aired);
|
System.out.println("Time: " + (System.currentTimeMillis() - time) + "ms " + simulatorData.blockTypesMap.size() + "/" + simulatorData.blockDataMap.size() + "/" + simulatorData.collisionDataMap.size() + "/" + simulatorData.airBlocks.size() + " " + recordMap.size());
|
||||||
if (simulatorData.tntList.isEmpty() && currentTick > toCalculate.getKey()) {
|
if (simulatorData.tntList.isEmpty() && currentTick > toCalculate.getKey()) {
|
||||||
simulatorData.airBlocks.forEach(pos -> previewRecord.addAir(new Vector(pos.x, pos.y, pos.z)));
|
previewRecord.setDestroyedBlocks(simulatorData.airBlocks());
|
||||||
|
previewRecord.setAccessedBlocks(vector -> true);
|
||||||
consumer.accept(previewRecord);
|
consumer.accept(previewRecord);
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,11 @@ package de.steamwar.bausystem.features.simulator.preview;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
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.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SimulatorData {
|
public class SimulatorData {
|
||||||
|
|
||||||
@ -64,7 +66,11 @@ public class SimulatorData {
|
|||||||
|
|
||||||
public BlockData getBlockData(int x, int y, int z) {
|
public BlockData getBlockData(int x, int y, int z) {
|
||||||
accessed++;
|
accessed++;
|
||||||
return blockDataMap.computeIfAbsent(new Pos(x, y, z), v -> {
|
Pos pos = new Pos(x, y, z);
|
||||||
|
if (airBlocks.contains(pos)) {
|
||||||
|
return AIR_BLOCK_DATA;
|
||||||
|
}
|
||||||
|
return blockDataMap.computeIfAbsent(pos, v -> {
|
||||||
cacheMisses++;
|
cacheMisses++;
|
||||||
return Simulator19.WORLD.getBlockAt(x, y, z).getBlockData();
|
return Simulator19.WORLD.getBlockAt(x, y, z).getBlockData();
|
||||||
});
|
});
|
||||||
@ -84,10 +90,16 @@ public class SimulatorData {
|
|||||||
public void clearBlock(Pos pos) {
|
public void clearBlock(Pos pos) {
|
||||||
aired++;
|
aired++;
|
||||||
airBlocks.add(pos);
|
airBlocks.add(pos);
|
||||||
blockDataMap.put(pos, AIR_BLOCK_DATA);
|
blockTypesMap.remove(pos);
|
||||||
|
blockDataMap.remove(pos);
|
||||||
|
collisionDataMap.remove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearBlocks(Set<Pos> poss) { // TODO: Optimize
|
public void clearBlocks(Set<Pos> poss) { // TODO: Optimize
|
||||||
poss.forEach(this::clearBlock);
|
poss.forEach(this::clearBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<Vector> airBlocks() {
|
||||||
|
return airBlocks.stream().map(pos -> new Vector(pos.x, pos.y, pos.z)).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import yapion.hierarchy.types.YAPIONArray;
|
import yapion.hierarchy.types.YAPIONArray;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
import yapion.hierarchy.types.YAPIONType;
|
import yapion.hierarchy.types.YAPIONType;
|
||||||
@ -138,6 +139,12 @@ public class TNTSimulator {
|
|||||||
return previewRecord != null && previewRecord.has(player);
|
return previewRecord != null && previewRecord.has(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void calcPreview(boolean force, Vector changedBlock) {
|
||||||
|
if (previewRecord == null || previewRecord.getAccessedBlocks().test(changedBlock)) {
|
||||||
|
calcPreview(force);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void calcPreview(boolean force) {
|
public void calcPreview(boolean force) {
|
||||||
if (!force && previewRecord == null) {
|
if (!force && previewRecord == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -194,17 +194,17 @@ public class TNTSimulatorListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockPlace(BlockPlaceEvent event) { // TODO: Optimize this
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
currentSimulator.values().forEach(simulator -> {
|
currentSimulator.values().forEach(simulator -> {
|
||||||
simulator.calcPreview(false);
|
simulator.calcPreview(false, event.getBlock().getLocation().toVector());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) { // TODO: Optimize this
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
currentSimulator.values().forEach(simulator -> {
|
currentSimulator.values().forEach(simulator -> {
|
||||||
simulator.calcPreview(false);
|
simulator.calcPreview(false, event.getBlock().getLocation().toVector());
|
||||||
});
|
});
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.tracer.show.EntityShowMode;
|
|||||||
import de.steamwar.bausystem.features.tracer.show.Record;
|
import de.steamwar.bausystem.features.tracer.show.Record;
|
||||||
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
|
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
@ -33,12 +34,18 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class PreviewRecord {
|
public class PreviewRecord {
|
||||||
|
|
||||||
private static final BlockData AIR_BLOCK_DATA = Material.AIR.createBlockData();
|
private static final BlockData AIR_BLOCK_DATA = Material.AIR.createBlockData();
|
||||||
|
|
||||||
private Set<Vector> destroyedBlocks = new HashSet<>();
|
@Setter
|
||||||
|
private Set<Vector> destroyedBlocks;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private Predicate<Vector> accessedBlocks;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Record record = new Record(null, (region, tntPosition) -> {});
|
private Record record = new Record(null, (region, tntPosition) -> {});
|
||||||
@ -49,10 +56,6 @@ public class PreviewRecord {
|
|||||||
return new HashSet<>(showModeMap.keySet());
|
return new HashSet<>(showModeMap.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAir(Vector destroyed) {
|
|
||||||
destroyedBlocks.add(destroyed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show(Player player) {
|
public void show(Player player) {
|
||||||
destroyedBlocks.forEach(vector -> {
|
destroyedBlocks.forEach(vector -> {
|
||||||
player.sendBlockChange(vector.toLocation(player.getWorld()), AIR_BLOCK_DATA);
|
player.sendBlockChange(vector.toLocation(player.getWorld()), AIR_BLOCK_DATA);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren