File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/concurrency Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .embeddedt .modernfix .forge .mixin .bugfix .concurrency ;
2+
3+ import com .llamalad7 .mixinextras .injector .wrapmethod .WrapMethod ;
4+ import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
5+ import net .minecraft .tags .TagKey ;
6+ import net .minecraftforge .registries .tags .ITag ;
7+ import org .jetbrains .annotations .NotNull ;
8+ import org .spongepowered .asm .mixin .Mixin ;
9+ import org .spongepowered .asm .mixin .Shadow ;
10+
11+ import java .util .Map ;
12+
13+ @ Mixin (targets = {"net/minecraftforge/registries/ForgeRegistryTagManager" })
14+ public class ForgeRegistryTagManagerMixin <V > {
15+ @ Shadow private volatile Map <TagKey <V >, ITag <V >> tags ;
16+
17+ /**
18+ * @author embeddedt (issue found by Uncandango)
19+ * @reason vanilla does not use the correct double-checked locking paradigm, which leads to race conditions
20+ */
21+ @ WrapMethod (method = "getTag" , remap = false )
22+ private ITag <V > getTagSafe (@ NotNull TagKey <V > name , Operation <ITag <V >> original ) {
23+ ITag <V > tag = this .tags .get (name );
24+ if (tag == null ) {
25+ synchronized (this ) {
26+ tag = original .call (name );
27+ }
28+ }
29+ return tag ;
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments