From fea7f8008ded3dbefe2d155ad3bd4886a7cb47e9 Mon Sep 17 00:00:00 2001 From: winterflyt <36+winterflyt@noreply.skidsolutions.xyz> Date: Mon, 30 Nov 2026 06:04:03 +0200 Subject: [PATCH] Upload files to "src/openonyx/movement" --- src/openonyx/movement/MovementPredictor.java | 69 +++++++++++++ src/openonyx/movement/PredictionCursor.java | 30 ++++++ src/openonyx/movement/PredictionTrack.java | 98 +++++++++++++++++++ .../movement/PredictionTrackCallback.java | 23 +++++ .../movement/PredictionTrackCallback2.java | 20 ++++ 5 files changed, 240 insertions(+) create mode 100644 src/openonyx/movement/MovementPredictor.java create mode 100644 src/openonyx/movement/PredictionCursor.java create mode 100644 src/openonyx/movement/PredictionTrack.java create mode 100644 src/openonyx/movement/PredictionTrackCallback.java create mode 100644 src/openonyx/movement/PredictionTrackCallback2.java diff --git a/src/openonyx/movement/MovementPredictor.java b/src/openonyx/movement/MovementPredictor.java new file mode 100644 index 0000000..11e9c7b --- /dev/null +++ b/src/openonyx/movement/MovementPredictor.java @@ -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 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() { + } +} diff --git a/src/openonyx/movement/PredictionCursor.java b/src/openonyx/movement/PredictionCursor.java new file mode 100644 index 0000000..2e1fd4b --- /dev/null +++ b/src/openonyx/movement/PredictionCursor.java @@ -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; + } +} diff --git a/src/openonyx/movement/PredictionTrack.java b/src/openonyx/movement/PredictionTrack.java new file mode 100644 index 0000000..42d79d9 --- /dev/null +++ b/src/openonyx/movement/PredictionTrack.java @@ -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 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 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 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 L() { + return new PredictionTrackCallback2(this); + } +} diff --git a/src/openonyx/movement/PredictionTrackCallback.java b/src/openonyx/movement/PredictionTrackCallback.java new file mode 100644 index 0000000..d9b3882 --- /dev/null +++ b/src/openonyx/movement/PredictionTrackCallback.java @@ -0,0 +1,23 @@ +package openonyx.movement; + +import java.util.Iterator; + +class PredictionTrackCallback implements Iterator { + 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; + } +} diff --git a/src/openonyx/movement/PredictionTrackCallback2.java b/src/openonyx/movement/PredictionTrackCallback2.java new file mode 100644 index 0000000..cfa1a11 --- /dev/null +++ b/src/openonyx/movement/PredictionTrackCallback2.java @@ -0,0 +1,20 @@ +package openonyx.movement; + +import java.util.Iterator; + +class PredictionTrackCallback2 implements Iterator { + private int H; + + public SimulatedTickState L() { + return this.predictionTrack.L(this.H++); + } + + @Override + public boolean hasNext() { + return true; + } + + PredictionTrackCallback2(PredictionTrack predictionTrack) { + this.predictionTrack = predictionTrackx; + } +}