Skip to content

Commit 87c977a

Browse files
committed
Patch concurrency issue in ForgeRegistryTagManager
1 parent 54e55e7 commit 87c977a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

0 commit comments

Comments
 (0)