Upload files to "src/openonyx/movement"
This commit is contained in:
1 parent
6628e46ab4
commit
fea7f8008d
5 files changed
+240
No files matched your search
@@ -0,0 +1,69 @@
|
|||||||
|
package openonyx.movement;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import meteordevelopment.orbit.EventHandler;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import openonyx.configuration.internal.MovementInputEvent;
|
||||||
|
import openonyx.configuration.internal.PreTickEvent;
|
||||||
|
import openonyx.core.MinecraftAccess;
|
||||||
|
import openonyx.utilities.MovementInputState;
|
||||||
|
import openonyx.utilities.PlayerUtils;
|
||||||
|
|
||||||
|
public final class MovementPredictor implements MinecraftAccess {
|
||||||
|
private PredictionTrack predictionTrack;
|
||||||
|
public static final MovementPredictor INSTANCE = new MovementPredictor();
|
||||||
|
private final Map<EntityPlayer, PredictionTrack> predictionTrackMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@EventHandler(priority = -10)
|
||||||
|
private void onMovementInput(MovementInputEvent movementInputEvent) {
|
||||||
|
this.L(movementInputEvent.getMovementInputState(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PredictionTrack L() {
|
||||||
|
MovementPredictor movementPredictor1 = this;
|
||||||
|
PredictionTrack predictionTrackx = movementPredictor1.predictionTrack;
|
||||||
|
if (movementPredictor1.predictionTrack != null) {
|
||||||
|
return predictionTrackx;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimulatedPlayer simulatedPlayer = SimulatedPlayer.L(SimulatedPlayerInput.L(PlayerUtils.L(mc.thePlayer)));
|
||||||
|
PredictionTrack predictionTrack1 = new PredictionTrack(simulatedPlayer);
|
||||||
|
return movementPredictor1.predictionTrack = predictionTrack1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = 1000)
|
||||||
|
private void onPreTick(PreTickEvent preTickEvent) {
|
||||||
|
this.predictionTrackMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void L(MovementInputState movementInputState, boolean bl) {
|
||||||
|
if (mc.thePlayer != null) {
|
||||||
|
if (!bl
|
||||||
|
|| this.predictionTrack == null
|
||||||
|
|| !this.predictionTrack.getSimulatedPlayer().getSimulatedPlayerInput().getMovementInputState().equals(movementInputState)) {
|
||||||
|
SimulatedPlayer simulatedPlayer = SimulatedPlayer.L(SimulatedPlayerInput.L(movementInputState));
|
||||||
|
this.predictionTrack = new PredictionTrack(simulatedPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PredictionTrack d(EntityPlayer entityPlayer) {
|
||||||
|
return this.predictionTrackMap
|
||||||
|
.computeIfAbsent(entityPlayer, entityPlayer1 -> new PredictionTrack(SimulatedPlayer.L(entityPlayer1, SimulatedPlayerInput.L(entityPlayer1))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = 500)
|
||||||
|
private void onMovementInput3(MovementInputEvent movementInputEvent) {
|
||||||
|
this.predictionTrack = null;
|
||||||
|
this.L(movementInputEvent.getMovementInputState(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onMovementInput2(MovementInputEvent movementInputEvent) {
|
||||||
|
this.L(movementInputEvent.getMovementInputState(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MovementPredictor() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package openonyx.movement;
|
||||||
|
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
|
|
||||||
|
public class PredictionCursor implements SimulatedEntity {
|
||||||
|
private int H;
|
||||||
|
private final PredictionTrack predictionTrack;
|
||||||
|
|
||||||
|
public PredictionCursor(PredictionTrack predictionTrack) {
|
||||||
|
this.predictionTrack = predictionTrackx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int L() {
|
||||||
|
return this.H;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vec3 pos() {
|
||||||
|
return this.predictionTrack.L(this.H).pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void L() {
|
||||||
|
this.H++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PredictionTrack getPredictionTrack() {
|
||||||
|
return this.predictionTrack;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package openonyx.movement;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
|
public class PredictionTrack {
|
||||||
|
private final List<SimulatedTickState> simulatedTickStates = new ArrayList<>();
|
||||||
|
private final SimulatedPlayer simulatedPlayer;
|
||||||
|
private final ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
|
||||||
|
private int e;
|
||||||
|
|
||||||
|
public SimulatedPlayer getSimulatedPlayer() {
|
||||||
|
return this.simulatedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PredictionTrack(SimulatedPlayer simulatedPlayer) {
|
||||||
|
this.simulatedPlayer = simulatedPlayerx;
|
||||||
|
this.simulatedTickStates.add(new SimulatedTickState(simulatedPlayerx));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<SimulatedTickState> L(int i, int j) {
|
||||||
|
if (j >= 1200) {
|
||||||
|
throw new IllegalStateException("tried to simulate a player for more than a minute!");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.L(j + 1);
|
||||||
|
return new PredictionTrackCallback(this, i, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
// $VF: Could not inline inconsistent finally blocks
|
||||||
|
// Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
|
||||||
|
public void L(int i) {
|
||||||
|
if (i < 0) {
|
||||||
|
throw new IllegalStateException("ticks may not be negative");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.e < i) {
|
||||||
|
this.reentrantReadWriteLock.writeLock().lock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (this.e < i) {
|
||||||
|
this.simulatedPlayer.L();
|
||||||
|
this.simulatedTickStates.add(new SimulatedTickState(this.simulatedPlayer));
|
||||||
|
this.e++;
|
||||||
|
}
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
this.reentrantReadWriteLock.writeLock().unlock();
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.reentrantReadWriteLock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// $VF: Could not inline inconsistent finally blocks
|
||||||
|
// Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
|
||||||
|
public SimulatedTickState L(int i) {
|
||||||
|
this.L(i);
|
||||||
|
this.reentrantReadWriteLock.readLock().lock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
simulatedTickState = this.simulatedTickStates.get(i);
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
this.reentrantReadWriteLock.readLock().unlock();
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.reentrantReadWriteLock.readLock().unlock();
|
||||||
|
return simulatedTickState;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $VF: Could not inline inconsistent finally blocks
|
||||||
|
// Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
|
||||||
|
public List<SimulatedTickState> L(int i, int j) {
|
||||||
|
if (j >= 1200) {
|
||||||
|
throw new IllegalStateException("tried to simulate a player for more than a minute!");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.L(j + 1);
|
||||||
|
this.reentrantReadWriteLock.readLock().lock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
list = List.copyOf(this.simulatedTickStates.subList(i, j + 1));
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
this.reentrantReadWriteLock.readLock().unlock();
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.reentrantReadWriteLock.readLock().unlock();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<SimulatedTickState> L() {
|
||||||
|
return new PredictionTrackCallback2(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package openonyx.movement;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
class PredictionTrackCallback implements Iterator<SimulatedTickState> {
|
||||||
|
private int i;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return this.i <= this.H;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimulatedTickState L() {
|
||||||
|
return this.predictionTrack.L(this.i++);
|
||||||
|
}
|
||||||
|
|
||||||
|
PredictionTrackCallback(PredictionTrack predictionTrack, int i, int j) {
|
||||||
|
this.predictionTrack = predictionTrackx;
|
||||||
|
this.e = ix;
|
||||||
|
this.H = j;
|
||||||
|
this.i = this.e;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package openonyx.movement;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
class PredictionTrackCallback2 implements Iterator<SimulatedTickState> {
|
||||||
|
private int H;
|
||||||
|
|
||||||
|
public SimulatedTickState L() {
|
||||||
|
return this.predictionTrack.L(this.H++);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PredictionTrackCallback2(PredictionTrack predictionTrack) {
|
||||||
|
this.predictionTrack = predictionTrackx;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user