Improved Thread Safety in BlocksHelper
This commit is contained in:
parent
0a438ae0e4
commit
96820cff84
1 changed files with 8 additions and 1 deletions
|
@ -31,7 +31,12 @@ public class BlocksHelper {
|
||||||
public static final Direction[] HORIZONTAL = makeHorizontal();
|
public static final Direction[] HORIZONTAL = makeHorizontal();
|
||||||
public static final Direction[] DIRECTIONS = Direction.values();
|
public static final Direction[] DIRECTIONS = Direction.values();
|
||||||
|
|
||||||
private static final MutableBlockPos POS = new MutableBlockPos();
|
private static final ThreadLocal<MutableBlockPos> TL_POS = new ThreadLocal<>(){
|
||||||
|
@Override
|
||||||
|
protected MutableBlockPos initialValue() {
|
||||||
|
return new MutableBlockPos();
|
||||||
|
}
|
||||||
|
};
|
||||||
protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
|
protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
|
||||||
protected static final BlockState WATER = Blocks.WATER.defaultBlockState();
|
protected static final BlockState WATER = Blocks.WATER.defaultBlockState();
|
||||||
|
|
||||||
|
@ -76,6 +81,7 @@ public class BlocksHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) {
|
public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) {
|
||||||
|
final MutableBlockPos POS = TL_POS.get();
|
||||||
POS.set(pos);
|
POS.set(pos);
|
||||||
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
|
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
|
||||||
POS.setY(POS.getY() - 1);
|
POS.setY(POS.getY() - 1);
|
||||||
|
@ -84,6 +90,7 @@ public class BlocksHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) {
|
public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) {
|
||||||
|
final MutableBlockPos POS = TL_POS.get();
|
||||||
POS.set(pos);
|
POS.set(pos);
|
||||||
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
|
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
|
||||||
POS.move(dx, dy, dz);
|
POS.move(dx, dy, dz);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue