Files
OpenOnyx/src/openonyx/movement/PredictionTrack.java
T

99 lines
3.3 KiB
Java

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);
}
}