ldtteam / minecolonies-features

This is a repo only to discuss minecolonies features (requested and planned)
10 stars 3 forks source link

Add a tag to recognise tools which don't take durability damage #641

Closed Akjosch closed 1 year ago

Akjosch commented 2 years ago

Prerequisites

Context

Is your feature request related to a problem?

There are some mods which use tools to craft their recipes. In particular, Harvestcraft and Croptopia have all those pans, cutting boards and whatnot. Those tools don't have durability, nor are they used up in crafting. I like to call them "catalyst tools".

When telling the assistant cook (as an example) to craft a stack of those, they don't recognise them as tools, instead filing them as "secondary outputs", on account of them not having any durability. The comparison then checks for the amount of those catalysts there is compared to the amount of crafts to be done, and requests (one) more each time the comparison turns out to be "fewer catalyst tools". This means that they'd eventually request 64 of those tools for each stack of items they need to craft, instead of reusing the one they already have.

For reference, the check is done here: https://github.com/ldtteam/minecolonies/blob/version/main/src/api/java/com/minecolonies/api/crafting/RecipeStorage.java#L251

Feature description

Suggested changes:

  1. Add a tag (minecolonies:tool for example) which would mark those tools as such. This can then be configured via a datapack. The Croptopia presets would put those tag on croptopia:food_press, croptopa:frying_pan, croptopia:cooking_pot and croptopia:mortat_and_pestle, for example.
  2. Check for the tag in https://github.com/ldtteam/minecolonies/blob/version/main/src/api/java/com/minecolonies/api/crafting/RecipeStorage.java#L251 and add those tools to the list.
  3. Make sure fullfillRecipeAndCopy() doesn't damage such tools around https://github.com/ldtteam/minecolonies/blob/version/main/src/api/java/com/minecolonies/api/crafting/RecipeStorage.java#L537-L571
  4. Fix whatever other bugs this triggers.

Alternatively:

  1. Same as Step 1 above
  2. Compare inputs and outputs to automatically detect such catalysts
  3. When requesting items, assume that one such is enough for any amount of crafts, don't request it if it's already there, and don't request more than one.
  4. Same as Step 4 above

Notes or related things

Relevant past PR: https://github.com/ldtteam/minecolonies/pull/6587


Viewers

uecasm commented 2 years ago

FWIW, I tested this in 1.16 with Pam's and it worked fine (at least until the assistant ran into ldtteam/minecolonies#8103, but that might just have been me not waiting long enough afterward) -- only one cutting board was requested when making 16x the base recipe, and they did make the final items just fine.

I haven't checked 1.18 yet since Pam's isn't out for that, but perhaps it's something specific to that, or specific to some implementation quirk of another mod's recipes?

Akjosch commented 2 years ago

In case of Croptopia, they implement the functionality by overriding getContainerItem(ItemStack) and gasContainerItem(ItemStack) in their "catalyst" items, and have the former return a copy of themselves. I think that's roughly the same functions water bottles use (they return empty bottles), but I didn't check Minecraft code.

Reference: https://github.com/ExcessiveAmountsOfZombies/Croptopia/blob/master/forge/src/main/java/me/thonk/croptopia/items/CookingUtensil.java

Moobien commented 2 years ago

This honestly is something needed

Thodor12 commented 1 year ago

Fixed