Skip to content

Commit 89d4dd1

Browse files
committed
Add 1.20.2 support
1 parent e8d05b5 commit 89d4dd1

3 files changed

Lines changed: 49 additions & 16 deletions

File tree

libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# Minecraft
44
minecraft_version = "1.20.4"
5-
minecraft_required = "~1.20.3-"
6-
minecraft_compatible = "1.20.3,1.20.4,1.20.5,1.20.6"
5+
minecraft_required = "~1.20.2-"
6+
minecraft_compatible = "1.20.2,1.20.3,1.20.4,1.20.5,1.20.6"
77

88
fabric_loader = "0.15.+"
99

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import net.minecraft.world.inventory.CraftingContainer;
3434
import net.minecraft.world.inventory.ResultContainer;
3535
import net.minecraft.world.inventory.Slot;
36+
import net.minecraft.world.item.Item;
3637
import net.minecraft.world.item.ItemStack;
3738
import net.minecraft.world.item.crafting.CraftingRecipe;
3839
import net.minecraft.world.item.crafting.Recipe;
@@ -51,6 +52,11 @@ public final class MixinHooks {
5152
private static final MethodHandle recipe$assemble = Reflector.virtual(Recipe.class, "method_8116",
5253
MethodType.methodType(ItemStack.class, Container.class, RegistryAccess.class));
5354

55+
private static final MethodHandle item$onCraftedBy = Reflector.virtual(
56+
Item.class, MethodType.methodType(void.class, ItemStack.class, Level.class, Player.class),
57+
"method_54465", "method_7843"
58+
);
59+
5460
public static boolean hascachedrecipe = false;
5561

5662
public static Recipe<CraftingContainer> lastRecipe;
@@ -64,11 +70,7 @@ public static void slotChangedCraftingGrid(Level level, CraftingContainer inv, R
6470
if (recipe == null || !recipe.value().matches(inv, level)) recipe = findRecipe(inv, level);
6571

6672
if (recipe != null) {
67-
try {
68-
itemstack = (ItemStack) recipe$assemble.invoke(recipe.value(), inv, level.registryAccess());
69-
} catch (Throwable t) {
70-
throw new AssertionError(t);
71-
}
73+
itemstack = durian(recipe$assemble, recipe.value(), inv, level.registryAccess());
7274
}
7375

7476
result.setItem(0, itemstack);
@@ -89,7 +91,7 @@ public static ItemStack handleShiftCraft(Player player, AbstractContainerMenu co
8991
ItemStack recipeOutput = resultSlot.getItem().copy();
9092
outputCopy = recipeOutput.copy();
9193

92-
recipeOutput.getItem().onCraftedBy(recipeOutput, player.level(), player);
94+
durian(item$onCraftedBy, recipeOutput.getItem(), recipeOutput, player.level(), player);
9395

9496
if (!player.level().isClientSide && !((ContainerAccessor) container).insert(recipeOutput, outStart, outEnd, true)) {
9597
duck.setCheckMatrixChanges(true);
@@ -128,4 +130,12 @@ public static RecipeHolder<CraftingRecipe> findRecipe(CraftingContainer inv, Lev
128130
public static <C extends Container, T extends Recipe<C>> RecipeHolder<T> coerce(RecipeHolder<?> in) {
129131
return (RecipeHolder<T>) in;
130132
}
133+
134+
public static <T> T durian(MethodHandle handle, Object... objects) {
135+
try {
136+
return (T) handle.invokeWithArguments(objects);
137+
} catch (Throwable t) {
138+
throw new AssertionError(t);
139+
}
140+
}
131141
}

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)