9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-24 17:39:30 +00:00

Clear placement info

This commit is contained in:
XiaoMoMi
2025-02-13 05:10:29 +08:00
parent 8b8a0e256b
commit 02c7ce3904
2 changed files with 25 additions and 1 deletions

View File

@@ -533,7 +533,11 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
.map(Optional::get)
.toList();
List<Object> ingredients = RecipeUtils.getIngredientsFromShapedRecipe(getNMSRecipe(id));
Object shapedRecipe = getNMSRecipe(id);
if (VersionHelper.isVersionNewerThan1_21_2()) {
Reflections.field$ShapedRecipe$placementInfo.set(shapedRecipe, null);
}
List<Object> ingredients = RecipeUtils.getIngredientsFromShapedRecipe(shapedRecipe);
injectIngredients(ingredients, actualIngredients);
}
@@ -541,6 +545,9 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
private static void injectShapelessRecipe(Key id, Recipe<ItemStack> recipe) throws ReflectiveOperationException {
List<Ingredient<ItemStack>> actualIngredients = ((CustomShapelessRecipe<ItemStack>) recipe).ingredients();
Object shapelessRecipe = getNMSRecipe(id);
if (VersionHelper.isVersionNewerThan1_21_2()) {
Reflections.field$ShapelessRecipe$placementInfo.set(shapelessRecipe, null);
}
List<Object> ingredients = (List<Object>) Reflections.field$ShapelessRecipe$ingredients.get(shapelessRecipe);
injectIngredients(ingredients, actualIngredients);
}

View File

@@ -4007,6 +4007,23 @@ public class Reflections {
)
);
public static final Class<?> clazz$PlacementInfo = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("world.item.crafting.PlacementInfo")
)
);
// 1.21.2+
public static final Field field$ShapelessRecipe$placementInfo =
ReflectionUtils.getDeclaredField(
clazz$ShapelessRecipe, clazz$PlacementInfo, 0
);
public static final Field field$ShapedRecipe$placementInfo =
ReflectionUtils.getDeclaredField(
clazz$ShapedRecipe, clazz$PlacementInfo, 0
);
public static final Field field$ShapelessRecipe$ingredients =
Optional.ofNullable(ReflectionUtils.getDeclaredField(clazz$ShapelessRecipe, List.class, 0))
.orElse(ReflectionUtils.getDeclaredField(clazz$ShapelessRecipe, clazz$NonNullList, 0));