BlockStatePredictionHandler.java
net.minecraft.client.multiplayer.prediction.BlockStatePredictionHandler
信息
- 全限定名:net.minecraft.client.multiplayer.prediction.BlockStatePredictionHandler
- 类型:public class
- 包:net.minecraft.client.multiplayer.prediction
- 源码路径:src/main/java/net/minecraft/client/multiplayer/prediction/BlockStatePredictionHandler.java
- 起始行号:L15
- 实现:AutoCloseable
- 职责:
TODO
字段/常量
-
serverVerifiedStates- 类型:
Long2ObjectOpenHashMap<BlockStatePredictionHandler.ServerVerifiedState> - 修饰符:
private final - 源码定位:
L16 - 说明:
TODO
- 类型:
-
currentSequenceNr- 类型:
int - 修饰符:
private - 源码定位:
L17 - 说明:
TODO
- 类型:
-
isPredicting- 类型:
boolean - 修饰符:
private - 源码定位:
L18 - 说明:
TODO
- 类型:
-
lastTeleportSequence- 类型:
int - 修饰符:
private - 源码定位:
L19 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.multiplayer.prediction.BlockStatePredictionHandler.ServerVerifiedState- 类型:
class - 修饰符:
private static - 源码定位:
L79 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public void retainKnownServerState(BlockPos pos, BlockState state, LocalPlayer player) @ L21
- 方法名:retainKnownServerState
- 源码定位:L21
- 返回类型:void
- 修饰符:public
参数:
- pos: BlockPos
- state: BlockState
- player: LocalPlayer
说明:
TODO
public boolean updateKnownServerState(BlockPos pos, BlockState blockState) @ L31
- 方法名:updateKnownServerState
- 源码定位:L31
- 返回类型:boolean
- 修饰符:public
参数:
- pos: BlockPos
- blockState: BlockState
说明:
TODO
public void endPredictionsUpTo(int sequence, ClientLevel clientLevel) @ L41
- 方法名:endPredictionsUpTo
- 源码定位:L41
- 返回类型:void
- 修饰符:public
参数:
- sequence: int
- clientLevel: ClientLevel
说明:
TODO
public BlockStatePredictionHandler startPredicting() @ L55
- 方法名:startPredicting
- 源码定位:L55
- 返回类型:BlockStatePredictionHandler
- 修饰符:public
参数:
- 无
说明:
TODO
public void close() @ L61
- 方法名:close
- 源码定位:L61
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public int currentSequence() @ L66
- 方法名:currentSequence
- 源码定位:L66
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public void onTeleport() @ L70
- 方法名:onTeleport
- 源码定位:L70
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isPredicting() @ L74
- 方法名:isPredicting
- 源码定位:L74
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class BlockStatePredictionHandler implements AutoCloseable {
private final Long2ObjectOpenHashMap<BlockStatePredictionHandler.ServerVerifiedState> serverVerifiedStates = new Long2ObjectOpenHashMap<>();
private int currentSequenceNr;
private boolean isPredicting;
private int lastTeleportSequence = -1;
public void retainKnownServerState(BlockPos pos, BlockState state, LocalPlayer player) {
this.serverVerifiedStates
.compute(
pos.asLong(),
(key, serverVerifiedState) -> serverVerifiedState != null
? serverVerifiedState.setSequence(this.currentSequenceNr)
: new BlockStatePredictionHandler.ServerVerifiedState(this.currentSequenceNr, state, player.position())
);
}
public boolean updateKnownServerState(BlockPos pos, BlockState blockState) {
BlockStatePredictionHandler.ServerVerifiedState serverVerifiedState = this.serverVerifiedStates.get(pos.asLong());
if (serverVerifiedState == null) {
return false;
} else {
serverVerifiedState.setBlockState(blockState);
return true;
}
}
public void endPredictionsUpTo(int sequence, ClientLevel clientLevel) {
ObjectIterator<Entry<BlockStatePredictionHandler.ServerVerifiedState>> stateIterator = this.serverVerifiedStates.long2ObjectEntrySet().iterator();
while (stateIterator.hasNext()) {
Entry<BlockStatePredictionHandler.ServerVerifiedState> next = stateIterator.next();
BlockStatePredictionHandler.ServerVerifiedState serverVerifiedState = next.getValue();
if (serverVerifiedState.sequence <= sequence) {
BlockPos pos = BlockPos.of(next.getLongKey());
stateIterator.remove();
clientLevel.syncBlockState(pos, serverVerifiedState.blockState, this.lastTeleportSequence < sequence ? serverVerifiedState.playerPos : null);
}
}
}
public BlockStatePredictionHandler startPredicting() {
this.currentSequenceNr++;
this.isPredicting = true;
return this;
}
@Override
public void close() {
this.isPredicting = false;
}
public int currentSequence() {
return this.currentSequenceNr;
}
public void onTeleport() {
this.lastTeleportSequence = this.currentSequenceNr;
}
public boolean isPredicting() {
return this.isPredicting;
}
@OnlyIn(Dist.CLIENT)
private static class ServerVerifiedState {
private final Vec3 playerPos;
private int sequence;
private BlockState blockState;
private ServerVerifiedState(int sequence, BlockState blockState, Vec3 playerPos) {
this.sequence = sequence;
this.blockState = blockState;
this.playerPos = playerPos;
}
private BlockStatePredictionHandler.ServerVerifiedState setSequence(int sequence) {
this.sequence = sequence;
return this;
}
private void setBlockState(BlockState blockState) {
this.blockState = blockState;
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
BlockPos.of()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: