9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-29 03:49:15 +00:00
This commit is contained in:
XiaoMoMi
2025-03-20 03:27:24 +08:00
parent 6b917b46ad
commit 70aa917cfb
16 changed files with 326 additions and 16 deletions

View File

@@ -195,7 +195,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
CraftEngine.instance().logger().warn("Failed to convert campfire recipe", e);
}
});
BUKKIT_RECIPE_FACTORIES.put(RecipeTypes.STONE_CUTTING, (key, recipe) -> {
BUKKIT_RECIPE_FACTORIES.put(RecipeTypes.STONECUTTING, (key, recipe) -> {
CustomStoneCuttingRecipe<ItemStack> ceRecipe = (CustomStoneCuttingRecipe<ItemStack>) recipe;
List<ItemStack> itemStacks = new ArrayList<>();
for (Holder<Key> item : ceRecipe.ingredient().items()) {
@@ -383,7 +383,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
this.byId.put(id, recipe);
this.byResult.computeIfAbsent(recipe.result().item().id(), k -> new ArrayList<>()).add(recipe);
for (Ingredient<ItemStack> ingredient : recipe.ingredientsInUse()) {
for (Holder<Key> holder : ingredient.items()) {
for (Holder<Key> holder : ingredient.items().stream().distinct().toList()) {
this.byIngredient.computeIfAbsent(holder.value(), k -> new ArrayList<>()).add(recipe);
}
}

View File

@@ -835,6 +835,7 @@ public class RecipeEventListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onSmithingTransform(PrepareSmithingEvent event) {
if (!ConfigManager.enableRecipeSystem()) return;
SmithingInventory inventory = event.getInventory();
if (!(inventory.getRecipe() instanceof SmithingTransformRecipe recipe)) return;
@@ -872,6 +873,21 @@ public class RecipeEventListener implements Listener {
CustomSmithingTransformRecipe<ItemStack> transformRecipe = (CustomSmithingTransformRecipe<ItemStack>) ceRecipe;
ItemStack processed = transformRecipe.assemble(new ItemBuildContext(this.plugin.adapt(player), ContextHolder.EMPTY), this.itemManager.wrap(base));
event.setResult(processed);
correctSmithingRecipeUsed(inventory, ceRecipe);
}
private void correctSmithingRecipeUsed(SmithingInventory inventory, Recipe<ItemStack> recipe) {
Object holderOrRecipe = recipeManager.getRecipeHolderByRecipe(recipe);
if (holderOrRecipe == null) {
// it's a vanilla recipe but not injected
return;
}
try {
Object resultInventory = Reflections.field$CraftResultInventory$resultInventory.get(inventory);
Reflections.field$ResultContainer$recipeUsed.set(resultInventory, holderOrRecipe);
} catch (ReflectiveOperationException e) {
plugin.logger().warn("Failed to correct used recipe", e);
}
}
private OptimizedIDItem<ItemStack> getOptimizedIDItem(@Nullable ItemStack itemStack) {

View File

@@ -4414,6 +4414,18 @@ public class Reflections {
)
);
public static final Class<?> clazz$CraftResultInventory = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleCBClass("inventory.CraftResultInventory")
)
);
public static final Field field$CraftResultInventory$resultInventory = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$CraftResultInventory, clazz$Container, 0
)
);
// 1.20.5+
public static final Method method$ItemStack$hurtAndBreak =
ReflectionUtils.getMethod(