From 96820cff84e0321d2dee037a41fa0f8ee650b733 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 28 Jan 2022 17:31:15 +0100 Subject: [PATCH] Improved Thread Safety in BlocksHelper --- src/main/java/ru/bclib/util/BlocksHelper.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/util/BlocksHelper.java b/src/main/java/ru/bclib/util/BlocksHelper.java index 6bf7c8b1..08bd64ad 100644 --- a/src/main/java/ru/bclib/util/BlocksHelper.java +++ b/src/main/java/ru/bclib/util/BlocksHelper.java @@ -31,7 +31,12 @@ public class BlocksHelper { public static final Direction[] HORIZONTAL = makeHorizontal(); public static final Direction[] DIRECTIONS = Direction.values(); - private static final MutableBlockPos POS = new MutableBlockPos(); + private static final ThreadLocal TL_POS = new ThreadLocal<>(){ + @Override + protected MutableBlockPos initialValue() { + return new MutableBlockPos(); + } + }; protected static final BlockState AIR = Blocks.AIR.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) { + final MutableBlockPos POS = TL_POS.get(); POS.set(pos); for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) { 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) { + final MutableBlockPos POS = TL_POS.get(); POS.set(pos); for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) { POS.move(dx, dy, dz);