Skip to content

Commit

Permalink
Port forward 1.20.2 support changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ampflower committed Jan 1, 2025
1 parent 66c9712 commit 616dc06
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/main/java/tfar/fastbench/MixinHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -142,4 +138,12 @@ public static NonNullList<ItemStack> copy(RecipeInput recipeInput) {
}
return list;
}

public static <T> T durian(MethodHandle handle, Object... objects) {
try {
return (T) handle.invokeWithArguments(objects);
} catch (Throwable t) {
throw new AssertionError(t);
}
}
}
39 changes: 31 additions & 8 deletions src/main/java/tfar/fastbench/quickbench/internal/Reflector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 616dc06

Please sign in to comment.