From 1d60cdb4002cb4b4fd43f4911978d911ad3cb9f6 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sun, 26 May 2024 08:37:34 -0700 Subject: [PATCH] Fix CME in StructureTemplate.Palette The cache needs to be a CHM to prevent CMEs. Since the only usage is compute() on static data, this is all we need to fix the threading issues here. --- .../StructureTemplate$PaletteMixin.java | 35 +++++++++++++++++++ src/main/resources/moonrise.accesswidener | 6 +++- src/main/resources/moonrise.mixins.json | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/StructureTemplate$PaletteMixin.java diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/StructureTemplate$PaletteMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/StructureTemplate$PaletteMixin.java new file mode 100644 index 00000000..5e943b5f --- /dev/null +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/StructureTemplate$PaletteMixin.java @@ -0,0 +1,35 @@ +package ca.spottedleaf.moonrise.mixin.chunk_system; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Mixin(StructureTemplate.Palette.class) +public abstract class StructureTemplate$PaletteMixin { + + @Shadow + private Map> cache; + + /** + * @reason Make cache CHM to prevent CME + * @author Spottedleaf + */ + @Inject( + method = "", + at = @At( + value = "RETURN" + ) + ) + private void makeCacheCHM(final CallbackInfo ci) { + this.cache = new ConcurrentHashMap<>(); + } +} diff --git a/src/main/resources/moonrise.accesswidener b/src/main/resources/moonrise.accesswidener index 10364af5..dd43b3c4 100644 --- a/src/main/resources/moonrise.accesswidener +++ b/src/main/resources/moonrise.accesswidener @@ -253,4 +253,8 @@ mutable field net/minecraft/client/multiplayer/ClientLevel entityStorage Lnet/mi # ClientLevel$EntityCallbacks accessible class net/minecraft/client/multiplayer/ClientLevel$EntityCallbacks -accessible method net/minecraft/client/multiplayer/ClientLevel$EntityCallbacks (Lnet/minecraft/client/multiplayer/ClientLevel;)V \ No newline at end of file +accessible method net/minecraft/client/multiplayer/ClientLevel$EntityCallbacks (Lnet/minecraft/client/multiplayer/ClientLevel;)V + + +# StructureTemplate$Palette +mutable field net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate$Palette cache Ljava/util/Map; \ No newline at end of file diff --git a/src/main/resources/moonrise.mixins.json b/src/main/resources/moonrise.mixins.json index 2fa10e2d..28dcf862 100644 --- a/src/main/resources/moonrise.mixins.json +++ b/src/main/resources/moonrise.mixins.json @@ -43,6 +43,7 @@ "chunk_system.ServerPlayerMixin", "chunk_system.SortedArraySetMixin", "chunk_system.StructureCheckMixin", + "chunk_system.StructureTemplate$PaletteMixin", "chunk_system.TicketMixin", "collisions.ArmorStandMixin", "collisions.ArrayVoxelShapeMixin",