SteamWar/BauSystem2.0
Archiviert
12
0

Fix Record lastVelocity calculation
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-09-02 12:11:22 +02:00
Ursprung a8aa431210
Commit 6400e20bbb
2 geänderte Dateien mit 6 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -22,41 +22,21 @@ package de.steamwar.bausystem.features.tracer;
import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.shared.Position;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.util.Vector;
import java.util.function.Supplier;
@Getter
public class TNTPosition extends Position {
@RequiredArgsConstructor
public static class CachingSupplier<T> implements Supplier<T> {
private final Supplier<T> supplier;
private boolean initialized;
private T value;
@Override
public T get() {
if (!initialized) {
value = supplier.get();
initialized = true;
}
return value;
}
}
private final Record.TNTRecord record;
private final int fuseTicks;
private final Vector previousLocation;
private final Vector velocity;
private final CachingSupplier<Vector> updateVelocity;
private final Vector updateVelocity;
private final boolean source;
private final boolean exploded;
public TNTPosition(Record.TNTRecord record, TNTPrimed entity, Vector previousLocation, Vector velocity, CachingSupplier<Vector> updateVelocity, boolean source, boolean exploded) {
public TNTPosition(Record.TNTRecord record, TNTPrimed entity, Vector previousLocation, Vector velocity, Vector updateVelocity, boolean source, boolean exploded) {
super(entity.getLocation().toVector());
this.record = record;
this.fuseTicks = entity.getFuseTicks();
@ -67,10 +47,6 @@ public class TNTPosition extends Position {
this.exploded = exploded;
}
public Vector getUpdateVelocity() {
return updateVelocity.get();
}
@Override
public String toString() {
return "Position{" +

Datei anzeigen

@ -118,21 +118,11 @@ public class Record {
private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) {
TNTPosition position;
if (positions.isEmpty()) {
position = new TNTPosition(this, tntPrimed, null, tntPrimed.getVelocity(), new TNTPosition.CachingSupplier<>(() -> null), source, exploded);
position = new TNTPosition(this, tntPrimed, null, tntPrimed.getVelocity(), null, source, exploded);
} else {
int currentSize = positions.size() + 1;
TNTPosition.CachingSupplier<Vector> velocitySupplier = new TNTPosition.CachingSupplier<>(() -> {
Vector current = null;
for (int i = currentSize - 1; i >= 0; i--) {
TNTPosition currentTNT = positions.get(i);
if ((currentTNT.getVelocity().getX() == 0 || currentTNT.getVelocity().getZ() == 0) && current != null) {
break;
}
current = currentTNT.getVelocity();
}
return current;
});
position = new TNTPosition(this, tntPrimed, positions.get(positions.size() - 1).getLocation(), tntPrimed.getVelocity(), velocitySupplier, source, exploded);
TNTPosition tntPosition = positions.get(positions.size() - 1);
Vector lastVelocity = tntPrimed.getLocation().toVector().clone().subtract(tntPosition.getLocation());
position = new TNTPosition(this, tntPrimed, positions.get(positions.size() - 1).getLocation(), tntPrimed.getVelocity(), lastVelocity, source, exploded);
}
positions.add(position);
TraceShowManager.show(region, position);