Skip to content

Commit

Permalink
Move invoking into it's own method
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Sep 14, 2024
1 parent d13a129 commit 37a5804
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/main/java/com/simibubi/create/compat/sodium/SodiumCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ private enum SpriteUtilCompat {
}
}, (sawSprite) -> {
try {
Class<?> clazz = Class.forName("net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil");

MethodType methodType = MethodType.methodType(Void.TYPE);
MethodHandle handle = lookup.findVirtual(clazz, "markSpriteActive", methodType);

handle.invoke(sawSprite);
invokeMarkSpriteActive(Class.forName("net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil"), sawSprite);
} catch (Throwable ignored) {}
}),
V0_6_API(() -> {
Expand All @@ -115,12 +110,8 @@ private enum SpriteUtilCompat {
try {
Field field = Class.forName("net.caffeinemc.mods.sodium.api.texture.SpriteUtil")
.getDeclaredField("INSTANCE");
Class<?> implClass = (Class<?>) field.get(null);

MethodType methodType = MethodType.methodType(Void.TYPE);
MethodHandle handle = lookup.findVirtual(implClass, "markSpriteActive", methodType);

handle.invoke(sawSprite);
invokeMarkSpriteActive((Class<?>) field.get(null), sawSprite);
} catch (Throwable ignored) {}
});

Expand All @@ -138,5 +129,12 @@ private static boolean checkMarkSpriteActiveSignature(Class<?> clazz) throws Thr
throw new IllegalStateException("markSpriteActive's signature has changed");
return true;
}

private static void invokeMarkSpriteActive(Class<?> clazz, TextureAtlasSprite sawSprite) throws Throwable {
MethodType methodType = MethodType.methodType(Void.TYPE);
MethodHandle handle = lookup.findVirtual(clazz, "markSpriteActive", methodType);

handle.invoke(sawSprite);
}
}
}

0 comments on commit 37a5804

Please sign in to comment.