minetest-mods / craftguide

:book: The most comprehensive Crafting Guide on Minetest
Other
43 stars 20 forks source link

API calls to learn recipes in Progressive Mode #61

Closed Wuzzy2 closed 5 years ago

Wuzzy2 commented 5 years ago

For progressive mode, I'd like to suggest a convenience function to “reveal” new recipes to a player by API call (as if the player had collected the item). I also suggest a callback that fires whenever a new recipe is revealed.

Use case: So for example, mods and games could reveal some basic but crucial “starter” recipes (like wood, torch). And they could reveal groups of items on certain events.

p-ouellette commented 5 years ago

I think the way to do this would be to make a mod that keeps track of "revealed" items and registers a recipe filter that returns recipes that use only revealed items. You might want to use the reveal data outside of the craft guide.

Wuzzy2 commented 5 years ago

I suppose this mod already knows which items are revealed, it seems silly to do it in any different mod.

kilbith commented 5 years ago

Hmm. I think @pauloue has a point. If the current API allows to do that in a separate mod, then the current API is good enough.

Wuzzy2 commented 5 years ago

If the current API allows to do that in a separate mod

How?

p-ouellette commented 5 years ago

Copy the code in the if progressive_mode block to your mod (along with any helper functions that it uses). Then add an API function to add to the saved inv_items. For the callback you will need to check for not already discovered items when you get the new ones here: https://github.com/minetest-mods/craftguide/blob/3f44ae00d20b7056718ee840ef76b62487bd5724/init.lua#L886-L887

kilbith commented 5 years ago

Closing. This might be re-opened if some limits in the current API are hit for your purposes.