diff --git a/src/main/java/tfar/fastbench/MixinHooks.java b/src/main/java/tfar/fastbench/MixinHooks.java index 4e5242f..fc0e006 100644 --- a/src/main/java/tfar/fastbench/MixinHooks.java +++ b/src/main/java/tfar/fastbench/MixinHooks.java @@ -68,11 +68,7 @@ public static void slotChangedCraftingGrid(Level level, CraftingContainer contai } if (recipe != null) { - try { - itemstack = (ItemStack) recipe$assemble.invoke(recipe.value(), input, level.registryAccess()); - } catch (Throwable t) { - throw new AssertionError(t); - } + itemstack = durian(recipe$assemble, recipe.value(), input, level.registryAccess()); } result.setItem(0, itemstack); @@ -142,4 +138,12 @@ public static NonNullList copy(RecipeInput recipeInput) { } return list; } + + public static T durian(MethodHandle handle, Object... objects) { + try { + return (T) handle.invokeWithArguments(objects); + } catch (Throwable t) { + throw new AssertionError(t); + } + } } diff --git a/src/main/java/tfar/fastbench/quickbench/internal/Reflector.java b/src/main/java/tfar/fastbench/quickbench/internal/Reflector.java index 6e96d3a..8471692 100644 --- a/src/main/java/tfar/fastbench/quickbench/internal/Reflector.java +++ b/src/main/java/tfar/fastbench/quickbench/internal/Reflector.java @@ -25,6 +25,7 @@ import java.lang.invoke.MethodType; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.Arrays; /** * @author Ampflower @@ -85,20 +86,42 @@ private static boolean signature(Method method, MethodType signature) { return true; } + private static MethodHandle virtual(MethodType signature, Class clazz, String reference) throws IllegalAccessException { + for (final var method : clazz.getMethods()) { + if (Modifier.isStatic(method.getModifiers())) { + continue; + } + if (!virtual(method, reference, signature)) { + continue; + } + return lookup.unreflect(method); + } + return null; + } + public static MethodHandle virtual(Class clazz, String reference, MethodType signature) { try { - for (final var method : clazz.getMethods()) { - if (Modifier.isStatic(method.getModifiers())) { - continue; - } - if (!virtual(method, reference, signature)) { - continue; - } - return lookup.unreflect(method); + final var method = virtual(signature, clazz, reference); + if (method != null) { + return method; } } catch (IllegalAccessException e) { throw new AssertionError(e); } throw new AssertionError(clazz + " has no such method: " + reference + signature); } + + public static MethodHandle virtual(Class clazz, MethodType signature, String... reference) { + try { + for (final var i : reference) { + final var method = virtual(signature, clazz, i); + if (method != null) { + return method; + } + } + } catch (IllegalAccessException e) { + throw new AssertionError(e); + } + throw new AssertionError(clazz + " has no such method: " + Arrays.toString(reference) + signature); + } }