diff --git a/modules/base/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/StructureTemplateMixin.java b/modules/base/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/StructureTemplateMixin.java index 450a0735..5f3439d7 100644 --- a/modules/base/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/StructureTemplateMixin.java +++ b/modules/base/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/StructureTemplateMixin.java @@ -47,6 +47,9 @@ public abstract class StructureTemplateMixin implements StructureTemplateExtensi @Shadow protected abstract void placeEntities(ServerLevelAccessor serverLevelAccessor, BlockPos blockPos, Mirror mirror, Rotation rotation, BlockPos blockPos2, @Nullable BoundingBox boundingBox, boolean bl); + @Unique + private static final ThreadLocal currentSettings = new ThreadLocal<>(); + @Inject( method = "placeInWorld", at = @At( @@ -55,7 +58,7 @@ public abstract class StructureTemplateMixin implements StructureTemplateExtensi ) ) private void grabSettings(ServerLevelAccessor level, BlockPos pos, BlockPos pivot, StructurePlaceSettings settings, - RandomSource random, int i, CallbackInfoReturnable cir, @Share("currentSettings") LocalRef currentSettings) { + RandomSource random, int i, CallbackInfoReturnable cir) { currentSettings.set(settings); } @@ -68,7 +71,7 @@ private void grabSettings(ServerLevelAccessor level, BlockPos pos, BlockPos pivo ) private List processEntityInfos(List original, ServerLevelAccessor level, BlockPos pos, Mirror mirror, Rotation rotation, - BlockPos pivot, @Nullable BoundingBox bounds, boolean finalizeMobs, @Share("currentSettings") LocalRef currentSettings) { + BlockPos pivot, @Nullable BoundingBox bounds, boolean finalizeMobs) { StructurePlaceSettings settings = currentSettings.get(); if (PortingLib.DEBUG) @@ -89,7 +92,7 @@ private List processEntityInfos(List o target = "Lnet/minecraft/core/BlockPos;offset(Lnet/minecraft/core/Vec3i;)Lnet/minecraft/core/BlockPos;" ) ) - private BlockPos dontProcessBlockPosTwice(BlockPos original, @Local StructureEntityInfo info, @Share("currentSettings") LocalRef currentSettings) { + private BlockPos dontProcessBlockPosTwice(BlockPos original, @Local StructureEntityInfo info) { StructurePlaceSettings settings = currentSettings.get(); if (settings != null) { // pos was already processed. return info.blockPos; @@ -97,6 +100,11 @@ private BlockPos dontProcessBlockPosTwice(BlockPos original, @Local StructureEnt return original; } + @Inject(method = "placeEntities", at = @At("RETURN")) + private void clearGrabbedSettings(CallbackInfo ci) { + currentSettings.remove(); // clear the settings when done to avoid leaking it + } + @ModifyExpressionValue( method = "placeEntities", at = @At(