Folia
Folia copied to clipboard
Unsafety in sort of important variable in CraftBlockStates
Expected behavior
The variable DISABLE_SNAPSHOT is kept as a static boolean on paper, but since paper is ticking single threaded, it doesn't really run into issues, every Folia call however, does not take this into consideration, I think this should be changed to ThreadLocal, otherwise this could possibly lead into issues?
# public static boolean DISABLE_SNAPSHOT = false; << PAPER.
public static final ThreadLocal<Boolean> DISABLE_SNAPSHOT = ThreadLocal.withInitial(() -> false);
this.snapshotDisabled = DISABLE_SNAPSHOT.get();
if (snapshotDisabled) {
this.snapshot = this.tileEntity;
} else {
this.snapshot = this.createSnapshot(tileEntity);
}
boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
CraftBlockEntityState.DISABLE_SNAPSHOT.set(!useSnapshot);
try {
// Paper end
CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockPosition, blockData, tileEntity);
blockState.setWorldHandle(craftBlock.getHandle()); // Inject the block's generator access
return blockState;
// Paper start
} finally {
CraftBlockEntityState.DISABLE_SNAPSHOT.set(prev);
}