mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-29 03:49:15 +00:00
0.0.35
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user