2222import java .io .IOException ;
2323import java .util .Deque ;
2424import java .util .Map ;
25+ import java .util .function .BiConsumer ;
2526
2627import com .google .common .collect .ImmutableMap ;
2728import com .google .common .collect .Queues ;
2829import com .google .gson .Gson ;
2930import com .google .gson .JsonElement ;
3031import com .google .gson .JsonObject ;
3132import com .google .gson .JsonParseException ;
33+ import jdk .nashorn .internal .codegen .CompilerConstants ;
3234import org .spongepowered .asm .mixin .Mixin ;
3335import org .spongepowered .asm .mixin .Unique ;
3436import org .spongepowered .asm .mixin .injection .At ;
@@ -50,12 +52,12 @@ public abstract class MixinLootManager extends MixinJsonDataLoader {
5052 @ Unique
5153 private ResourceManager resourceManager ;
5254
55+ // TODO: is reentrancy necessary?
5356 @ Unique
5457 private static ThreadLocal <Deque <LootManager >> lootContext = new ThreadLocal <Deque <LootManager >>();
5558
56- // TODO: is reentrancy necessary?
57- @ Inject (method = "apply" , at = @ At ("HEAD" ))
58- private void getResourceManager (Map <Identifier , JsonObject > map , ResourceManager resourceManager , Profiler profiler , CallbackInfo info ) {
59+ @ Redirect (method = "apply" , at = @ At (value = "INVOKE" , target = "java/util/Map.forEach (Ljava/util/function/BiConsumer;)V" ))
60+ private void handleContext (Map <Identifier , JsonObject > map , BiConsumer <Identifier , JsonObject > consumer , Map <Identifier , JsonObject > sameMap , ResourceManager resourceManager , Profiler profiler ) {
5961 this .resourceManager = resourceManager ;
6062 Deque <LootManager > que = lootContext .get ();
6163
@@ -65,13 +67,13 @@ private void getResourceManager(Map<Identifier, JsonObject> map, ResourceManager
6567 }
6668
6769 que .push ((LootManager ) (Object ) this );
68- }
6970
70- @ Inject (method = "apply" , at = @ At ("RETURN" ))
71- private void delResourceManager (CallbackInfo info ) {
72- // TODO: what if an exception is thrown?
73- resourceManager = null ;
74- lootContext .get ().pop ();
71+ try {
72+ map .forEach (consumer );
73+ } finally {
74+ this .resourceManager = null ;
75+ lootContext .get ().pop ();
76+ }
7577 }
7678
7779 @ Redirect (method = "method_20711" , at = @ At (value = "INVOKE" , target = "com/google/gson/Gson.fromJson (Lcom/google/gson/JsonElement;Ljava/lang/Class;)Ljava/lang/Object;" ))
0 commit comments