Skip to content

Commit

Permalink
Fix CME in StructureTemplate.Palette
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Spottedleaf committed May 26, 2024
1 parent 959fc80 commit 1d60cdb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<>();
}
}
6 changes: 5 additions & 1 deletion src/main/resources/moonrise.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions src/main/resources/moonrise.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"chunk_system.ServerPlayerMixin",
"chunk_system.SortedArraySetMixin",
"chunk_system.StructureCheckMixin",
"chunk_system.StructureTemplate$PaletteMixin",
"chunk_system.TicketMixin",
"collisions.ArmorStandMixin",
"collisions.ArrayVoxelShapeMixin",
Expand Down

0 comments on commit 1d60cdb

Please sign in to comment.