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.
This commit is contained in:
Spottedleaf
2024-05-26 08:37:34 -07:00
parent 959fc80c67
commit 1d60cdb400
3 changed files with 41 additions and 1 deletions

View File

@@ -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<Block, List<StructureTemplate.StructureBlockInfo>> cache;
/**
* @reason Make cache CHM to prevent CME
* @author Spottedleaf
*/
@Inject(
method = "<init>",
at = @At(
value = "RETURN"
)
)
private <K, V> void makeCacheCHM(final CallbackInfo ci) {
this.cache = new ConcurrentHashMap<>();
}
}

View File

@@ -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 <init> (Lnet/minecraft/client/multiplayer/ClientLevel;)V
accessible method net/minecraft/client/multiplayer/ClientLevel$EntityCallbacks <init> (Lnet/minecraft/client/multiplayer/ClientLevel;)V
# StructureTemplate$Palette
mutable field net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate$Palette cache Ljava/util/Map;

View File

@@ -43,6 +43,7 @@
"chunk_system.ServerPlayerMixin",
"chunk_system.SortedArraySetMixin",
"chunk_system.StructureCheckMixin",
"chunk_system.StructureTemplate$PaletteMixin",
"chunk_system.TicketMixin",
"collisions.ArmorStandMixin",
"collisions.ArrayVoxelShapeMixin",