Skip to content

Commit f040f66

Browse files
committed
Make backing maps in ItemProperties thread-safe
Helps prevent CMEs on Forge 1.16
1 parent 6bc2b5b commit f040f66

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.embeddedt.modernfix.common.mixin.safety;
2+
3+
import net.minecraft.client.renderer.item.ItemProperties;
4+
import net.minecraft.client.renderer.item.ItemPropertyFunction;
5+
import net.minecraft.resources.ResourceLocation;
6+
import net.minecraft.world.item.Item;
7+
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
8+
import org.spongepowered.asm.mixin.Final;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.Mutable;
11+
import org.spongepowered.asm.mixin.Shadow;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
import org.spongepowered.asm.mixin.injection.Inject;
14+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
15+
16+
import java.util.Map;
17+
import java.util.concurrent.ConcurrentHashMap;
18+
19+
@Mixin(value = ItemProperties.class, priority = 700)
20+
@ClientOnlyMixin
21+
public class ItemPropertiesMixin {
22+
@Shadow @Final @Mutable private static Map<ResourceLocation, ItemPropertyFunction> GENERIC_PROPERTIES;
23+
@Shadow @Final @Mutable private static Map<Item, Map<ResourceLocation, ItemPropertyFunction>> PROPERTIES;
24+
25+
@Inject(method = "<clinit>", at = @At("RETURN"))
26+
private static void useConcurrentMaps(CallbackInfo ci) {
27+
GENERIC_PROPERTIES = new ConcurrentHashMap<>(GENERIC_PROPERTIES);
28+
PROPERTIES = new ConcurrentHashMap<>(PROPERTIES);
29+
}
30+
}

0 commit comments

Comments
 (0)