Lolcroc / CraftingAutomat

A vanilla-flavoured autocrafter.
6 stars 9 forks source link

Drop vanilla recipe book ingredients checking #18

Open Lolcroc opened 2 years ago

Lolcroc commented 2 years ago

Instead bake the cost through simulation. Make sure to handle container items correctly (edge cases such as #14).

Hopefully fixes #5, #11, #13 and #14

AiDSl commented 2 years ago

@net.minecraft.world.level class level.getRecipeManager() @net.minecraft.world.item.crafting class RecipeManager.getRecipeFor() @net.minecraft.world.item.crafting class RecipeManager.getRecipesFor() @net.minecraft.world.item.crafting interface RecipeType CRAFTING

and container should be @net.minecraft.world.inventory.CraftingContainer in 1.18.2 or @net.minecraft.inventory.container.Container CraftingInventory in 1.19.2

and idk how to implment it,I only found what might come handy...

Lolcroc commented 2 years ago

@AiDSl That's exactly how the automat is currently handling recipes. I used this method because I noticed a lot of overlap between what my mod needs to do and what the vanilla recipe book does, such as checking ingredients and counting recipe output.

This method is not viable for complex recipes however. The vanilla recipe book does not include "dynamic recipes", such as fireworks, for the simple reason that the recipe book was not programmed to be able to calculate their recipe output and cost. Probably the reasoning here was that dynamic recipes would clutter the recipe book, and there was no simple method to resolve ambiguity of NBT data. Recipes with items that carry NBT data are notorious for unreliable behaviour in vanilla and modded minecraft (see e.g. MC-129057, MC-116905, and #14 for this mod).

The proposed solution is to drop the vanilla recipe book checking altogether, and write something of my own. The important feature to keep is to anticipate the cost of recipes from ingredients in the buffer (see this reply for a motivation). The algorithm that the recipe book uses is very involved and has poor mappings with no documentation, so I've had trouble redesigning it myself. If you have any suggestions feel free to reply to me here.

EDIT: The vanilla recipe book relies on the StackedContents class; I got it confused with RecipeManager that matches a crafting matrix to a recipe, which is independent from the process described above. The classes and methods you proposed are indeed needed for a new implementation (thanks for the research :)), although I really opened this issue for the technical details that need to go into redesigning what StackedContents does, but for complex recipes.