SteamWar/BauSystem2.0
Archiviert
12
0

Implement advanced TNTSimulator PreviewRecord
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-09-07 15:35:45 +02:00
Ursprung 12d0ecbf0e
Commit 1af342d2c3
6 geänderte Dateien mit 50 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.features.simulator.preview; package de.steamwar.bausystem.features.simulator.preview;
import de.steamwar.bausystem.features.simulator.TNTData; import de.steamwar.bausystem.features.simulator.TNTData;
import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -66,10 +67,12 @@ public class Simulator19 implements Simulator {
} }
int currentTick = 0; int currentTick = 0;
Map<TNT, Record.TNTRecord> recordMap = new HashMap<>();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
while (!tntList.isEmpty() || currentTick <= toCalculate.getKey()) { while (!tntList.isEmpty() || currentTick <= toCalculate.getKey()) {
List<List<Pair<TNTData, Integer>>> toSpawnInTick = toCalculate.getValue().get(currentTick); List<List<Pair<TNTData, Integer>>> toSpawnInTick = toCalculate.getValue().get(currentTick);
if (toSpawnInTick != null) { if (toSpawnInTick != null) {
int finalCurrentTick = currentTick;
toSpawnInTick.forEach(pairs -> { toSpawnInTick.forEach(pairs -> {
AtomicBoolean hasSomeLeft = new AtomicBoolean(true); AtomicBoolean hasSomeLeft = new AtomicBoolean(true);
while(hasSomeLeft.get()) { while(hasSomeLeft.get()) {
@ -84,6 +87,9 @@ public class Simulator19 implements Simulator {
tnt.setFuse(tnt.getFuse()); tnt.setFuse(tnt.getFuse());
tntList.add(tnt); tntList.add(tnt);
pair.setValue(pair.getValue() - 1); pair.setValue(pair.getValue() - 1);
Record.TNTRecord record = previewRecord.getRecord().spawn(finalCurrentTick);
record.source(pair.getKey().location.toVector(), new Vector(tnt.getVx(), tnt.getVy(), tnt.getVz()), tnt.getFuse());
recordMap.put(tnt, record);
} }
}); });
} }
@ -95,8 +101,10 @@ public class Simulator19 implements Simulator {
for (TNT tnt : tntList) { for (TNT tnt : tntList) {
if (tnt.tick()) { if (tnt.tick()) {
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());
} else {
recordMap.get(tnt).location(new Vector(tnt.getX(), tnt.getY(), tnt.getZ()), new Vector(tnt.getVx(), tnt.getVy(), tnt.getVz()), tnt.getFuse());
} }
previewRecord.add(tnt.getX(), tnt.getY(), tnt.getZ());
} }
tntList.removeAll(remove); tntList.removeAll(remove);
} }

Datei anzeigen

@ -130,7 +130,7 @@ public class TNTSimulator {
previewRecord = newRecord; previewRecord = newRecord;
if (newRecord == null) return; if (newRecord == null) return;
if (oldRecord != null) { if (oldRecord != null) {
new HashSet<>(oldRecord.getPlayers()).forEach(player -> { oldRecord.getPlayers().forEach(player -> {
oldRecord.hide(player); oldRecord.hide(player);
newRecord.show(player); newRecord.show(player);
}); });

Datei anzeigen

@ -19,38 +19,34 @@
package de.steamwar.bausystem.features.simulator.preview; package de.steamwar.bausystem.features.simulator.preview;
import de.steamwar.entity.REntityServer; import de.steamwar.bausystem.features.tracer.show.EntityShowMode;
import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData; 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.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
public class PreviewRecord { public class PreviewRecord {
private static final World WORLD = Bukkit.getWorlds().get(0);
private static final BlockData AIR_BLOCK_DATA = Material.AIR.createBlockData(); private static final BlockData AIR_BLOCK_DATA = Material.AIR.createBlockData();
private Set<Vector> vectorList = new HashSet<>();
private Set<Vector> destroyedBlocks = new HashSet<>(); private Set<Vector> destroyedBlocks = new HashSet<>();
@Getter @Getter
private Set<Player> players = new HashSet<>(); private Record record = new Record(null, (region, tntPosition) -> {});
private REntityServer rEntityServer = new REntityServer();
public void add(double x, double y, double z) { private Map<Player, EntityShowMode> showModeMap = new HashMap<>();
Vector vector = new Vector(x, y, z);
if (vectorList.add(vector)) { public Set<Player> getPlayers() {
RFallingBlockEntity entity = new RFallingBlockEntity(rEntityServer, vector.toLocation(WORLD), Material.RED_STAINED_GLASS); return new HashSet<>(showModeMap.keySet());
entity.setNoGravity(true);
}
} }
public void addAir(Vector destroyed) { public void addAir(Vector destroyed) {
@ -58,22 +54,31 @@ public class PreviewRecord {
} }
public void show(Player player) { public void show(Player player) {
if (players.add(player)) { showModeMap.computeIfAbsent(player, p -> {
rEntityServer.addPlayer(player);
destroyedBlocks.forEach(vector -> { destroyedBlocks.forEach(vector -> {
player.sendBlockChange(vector.toLocation(player.getWorld()), AIR_BLOCK_DATA); p.sendBlockChange(vector.toLocation(player.getWorld()), AIR_BLOCK_DATA);
});
ShowModeParameter showModeParameter = new ShowModeParameter();
showModeParameter.enableInterpolateY();
showModeParameter.enableInterpolateXZ();
showModeParameter.enableWater();
showModeParameter.enableCount();
showModeParameter.setTntPositionMaterial(Material.RED_STAINED_GLASS);
showModeParameter.setUpdatePositionMaterial(Material.WHITE_STAINED_GLASS);
showModeParameter.setExplosePositionMaterial(Material.RED_WOOL);
return new EntityShowMode(p, showModeParameter, 10);
}); });
}
} }
public boolean hide(Player player) { public boolean hide(Player player) {
if (players.remove(player)) { EntityShowMode showMode = showModeMap.remove(player);
rEntityServer.removePlayer(player); if (showMode != null) {
showMode.hide();
destroyedBlocks.forEach(vector -> { destroyedBlocks.forEach(vector -> {
Location location = vector.toLocation(player.getWorld()); Location location = vector.toLocation(player.getWorld());
player.sendBlockChange(location, location.getBlock().getBlockData()); player.sendBlockChange(location, location.getBlock().getBlockData());
}); });
} }
return players.isEmpty(); return showModeMap.isEmpty();
} }
} }

Datei anzeigen

@ -166,11 +166,11 @@ public class EntityShowMode implements ShowMode<TNTPosition> {
private REntity createEntity(Vector position, PositionType positionType) { private REntity createEntity(Vector position, PositionType positionType) {
Material material; Material material;
if (positionType == PositionType.TNT) { if (positionType == PositionType.TNT) {
material = Material.TNT; material = showModeParameter.getTntPositionMaterial();
} else if (positionType == PositionType.EXPLODE) { } else if (positionType == PositionType.EXPLODE) {
material = Material.RED_STAINED_GLASS; material = showModeParameter.getExplosePositionMaterial();
} else { } else {
material = Material.WHITE_STAINED_GLASS; material = showModeParameter.getUpdatePositionMaterial();
} }
RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, position.toLocation(player.getWorld()), material); RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, position.toLocation(player.getWorld()), material);
entity.setNoGravity(true); entity.setNoGravity(true);

Datei anzeigen

@ -45,10 +45,6 @@ public class Record {
return tnt.size(); return tnt.size();
} }
public void showAll(ShowMode<TNTPosition> traceShowMode) {
tnt.forEach(tntRecord -> tntRecord.getPositions().forEach(traceShowMode::show));
}
public TNTRecord spawn(long offset) { public TNTRecord spawn(long offset) {
TNTRecord record = new TNTRecord(this, offset, region); TNTRecord record = new TNTRecord(this, offset, region);
tnt.add(record); tnt.add(record);

Datei anzeigen

@ -20,6 +20,8 @@
package de.steamwar.bausystem.features.tracer.show; package de.steamwar.bausystem.features.tracer.show;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
@Getter @Getter
public class ShowModeParameter { public class ShowModeParameter {
@ -34,6 +36,15 @@ public class ShowModeParameter {
private boolean ticksSinceStart = false; private boolean ticksSinceStart = false;
private boolean microMotion = false; private boolean microMotion = false;
@Setter
private Material tntPositionMaterial = Material.TNT;
@Setter
private Material updatePositionMaterial = Material.WHITE_STAINED_GLASS;
@Setter
private Material explosePositionMaterial = Material.RED_STAINED_GLASS;
public void enableWater() { public void enableWater() {
this.water = true; this.water = true;
} }