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;
import de.steamwar.bausystem.features.simulator.TNTData;
import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.shared.Pair;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -66,10 +67,12 @@ public class Simulator19 implements Simulator {
}
int currentTick = 0;
Map<TNT, Record.TNTRecord> recordMap = new HashMap<>();
long time = System.currentTimeMillis();
while (!tntList.isEmpty() || currentTick <= toCalculate.getKey()) {
List<List<Pair<TNTData, Integer>>> toSpawnInTick = toCalculate.getValue().get(currentTick);
if (toSpawnInTick != null) {
int finalCurrentTick = currentTick;
toSpawnInTick.forEach(pairs -> {
AtomicBoolean hasSomeLeft = new AtomicBoolean(true);
while(hasSomeLeft.get()) {
@ -84,6 +87,9 @@ public class Simulator19 implements Simulator {
tnt.setFuse(tnt.getFuse());
tntList.add(tnt);
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) {
if (tnt.tick()) {
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);
}

Datei anzeigen

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

Datei anzeigen

@ -19,38 +19,34 @@
package de.steamwar.bausystem.features.simulator.preview;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import de.steamwar.bausystem.features.tracer.show.EntityShowMode;
import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
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 org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class PreviewRecord {
private static final World WORLD = Bukkit.getWorlds().get(0);
private static final BlockData AIR_BLOCK_DATA = Material.AIR.createBlockData();
private Set<Vector> vectorList = new HashSet<>();
private Set<Vector> destroyedBlocks = new HashSet<>();
@Getter
private Set<Player> players = new HashSet<>();
private REntityServer rEntityServer = new REntityServer();
private Record record = new Record(null, (region, tntPosition) -> {});
public void add(double x, double y, double z) {
Vector vector = new Vector(x, y, z);
if (vectorList.add(vector)) {
RFallingBlockEntity entity = new RFallingBlockEntity(rEntityServer, vector.toLocation(WORLD), Material.RED_STAINED_GLASS);
entity.setNoGravity(true);
}
private Map<Player, EntityShowMode> showModeMap = new HashMap<>();
public Set<Player> getPlayers() {
return new HashSet<>(showModeMap.keySet());
}
public void addAir(Vector destroyed) {
@ -58,22 +54,31 @@ public class PreviewRecord {
}
public void show(Player player) {
if (players.add(player)) {
rEntityServer.addPlayer(player);
showModeMap.computeIfAbsent(player, p -> {
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) {
if (players.remove(player)) {
rEntityServer.removePlayer(player);
EntityShowMode showMode = showModeMap.remove(player);
if (showMode != null) {
showMode.hide();
destroyedBlocks.forEach(vector -> {
Location location = vector.toLocation(player.getWorld());
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) {
Material material;
if (positionType == PositionType.TNT) {
material = Material.TNT;
material = showModeParameter.getTntPositionMaterial();
} else if (positionType == PositionType.EXPLODE) {
material = Material.RED_STAINED_GLASS;
material = showModeParameter.getExplosePositionMaterial();
} else {
material = Material.WHITE_STAINED_GLASS;
material = showModeParameter.getUpdatePositionMaterial();
}
RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, position.toLocation(player.getWorld()), material);
entity.setNoGravity(true);

Datei anzeigen

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

Datei anzeigen

@ -20,6 +20,8 @@
package de.steamwar.bausystem.features.tracer.show;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
@Getter
public class ShowModeParameter {
@ -34,6 +36,15 @@ public class ShowModeParameter {
private boolean ticksSinceStart = 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() {
this.water = true;
}