Skip to content

Commit 616dc06

Browse files
committed
Port forward 1.20.2 support changes
1 parent 66c9712 commit 616dc06

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

src/main/java/tfar/fastbench/MixinHooks.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ public static void slotChangedCraftingGrid(Level level, CraftingContainer contai
6868
}
6969

7070
if (recipe != null) {
71-
try {
72-
itemstack = (ItemStack) recipe$assemble.invoke(recipe.value(), input, level.registryAccess());
73-
} catch (Throwable t) {
74-
throw new AssertionError(t);
75-
}
71+
itemstack = durian(recipe$assemble, recipe.value(), input, level.registryAccess());
7672
}
7773

7874
result.setItem(0, itemstack);
@@ -142,4 +138,12 @@ public static NonNullList<ItemStack> copy(RecipeInput recipeInput) {
142138
}
143139
return list;
144140
}
141+
142+
public static <T> T durian(MethodHandle handle, Object... objects) {
143+
try {
144+
return (T) handle.invokeWithArguments(objects);
145+
} catch (Throwable t) {
146+
throw new AssertionError(t);
147+
}
148+
}
145149
}

src/main/java/tfar/fastbench/quickbench/internal/Reflector.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.lang.invoke.MethodType;
2626
import java.lang.reflect.Method;
2727
import java.lang.reflect.Modifier;
28+
import java.util.Arrays;
2829

2930
/**
3031
* @author Ampflower
@@ -85,20 +86,42 @@ private static boolean signature(Method method, MethodType signature) {
8586
return true;
8687
}
8788

89+
private static MethodHandle virtual(MethodType signature, Class<?> clazz, String reference) throws IllegalAccessException {
90+
for (final var method : clazz.getMethods()) {
91+
if (Modifier.isStatic(method.getModifiers())) {
92+
continue;
93+
}
94+
if (!virtual(method, reference, signature)) {
95+
continue;
96+
}
97+
return lookup.unreflect(method);
98+
}
99+
return null;
100+
}
101+
88102
public static MethodHandle virtual(Class<?> clazz, String reference, MethodType signature) {
89103
try {
90-
for (final var method : clazz.getMethods()) {
91-
if (Modifier.isStatic(method.getModifiers())) {
92-
continue;
93-
}
94-
if (!virtual(method, reference, signature)) {
95-
continue;
96-
}
97-
return lookup.unreflect(method);
104+
final var method = virtual(signature, clazz, reference);
105+
if (method != null) {
106+
return method;
98107
}
99108
} catch (IllegalAccessException e) {
100109
throw new AssertionError(e);
101110
}
102111
throw new AssertionError(clazz + " has no such method: " + reference + signature);
103112
}
113+
114+
public static MethodHandle virtual(Class<?> clazz, MethodType signature, String... reference) {
115+
try {
116+
for (final var i : reference) {
117+
final var method = virtual(signature, clazz, i);
118+
if (method != null) {
119+
return method;
120+
}
121+
}
122+
} catch (IllegalAccessException e) {
123+
throw new AssertionError(e);
124+
}
125+
throw new AssertionError(clazz + " has no such method: " + Arrays.toString(reference) + signature);
126+
}
104127
}

0 commit comments

Comments
 (0)