Closed neinwhal closed 2 years ago
I added an api.txt for locks in ccore. The locks API presently serve as an easy way for me to apply various lock status on a single node (rather than having multiple locked, unlocked variants etc) It is in used by the storage API as present in crates, and for the various work stations built with workbench API.
It is a bit more complicated than other APIs in the sense it's supposed to be used in conjunction with several factors and requirements. I don't think the API docs are fully adequate in explaining it, if you want a very simple example, look up how workbench/craftbench.lua
handles the various functions.
I'm changing this back to WIP status. Trying for faster ways to handle the data.
This is ready for review. No major changes in features from first version, apart from some minor added features - mainly to support an easy way of getting multiple outputs from a single recipe/input.
Code wise, the delay was for an optimization of the code, as well as rewrite of the data structure. Both of which has been successful, and led to a decrease of nearly half the time and more, to obtain the output variables. Notably, this should allow the crafting process to find instantaneous.
This is ready for review.
Gave workbench a good overall scan for organization and sampled a few of the commits. I feel good about the code and error handling so no concerns here. Good work on those optimization tweaks!
Update: As of 2210bd2940321f214e512ccef56a75d89d705840 ; I have rewritten the data structure and created one to support easily obtaining recipes with multiple outputs. Combined with optimization of the existing code (- much thanks to Amaz for some suggestions); The result of this is a cut of half the time and more for the crafting process, making the process feel instantaneous as intended. There is also so minor changes, that are reflected in
api.txt
Shapes Improvements
For more extensive documentation, refer to
shapes/api.txt
connects_to
andconnect_sides
, add shape-specific settings for them to.enabled
is now a thing alongsidedisabled
This list allows enabling of specific shapes (some that are disabled by default; i.e. sphere and panemc), other than that, ifenabled
is used but notdisabled
, all other shapes except the ones on theenabled
list are disabled.rotate_and_place
and support for multiple crafting recipes; refer to api.txtgroup:shapes
(nodeboxes) orgroup:shapes_mesh
(mesh) for easy identificationshapes.registered_shape[nodename]
- find if a node has registered shapesWorkbench
For those that haven't been following, the new workbench is completely different from the old one. Rather than creating a system to create crafting tables, workbench now provides a custom crafting API and a custom fuel API. These API can then be further used by other mods to create your own custom crafting tables and crafts with a lot of flexibility.
Workbench Crafting API
So why a new crafting API, doesn't minetest already provides one? Yes, but this provides much more features and flexibility. New features include;
transfer_meta
Transferring metadata from input item to output item. Uses a similar format as replacements, see api.txtmulti_id
andlistall
inapi.txt
(Why not automated - It can be, but with tested with current shapes recipes (~30000 crafts), it adds a total of 2 minutes extra loadtime, in contrast a targetted manual system doesn't require the system to do its searches, cutting that loadtime entirely)Most old features are supported as well, this includes;
replacements
minetest.register_craft
, all old crafts registered can be retrieved from workbench crafting API (exception of toolrepair, because there isn't a way to extract it)To note;
minetest.register_craft
is NOT forward-compatible with workbench crafting. This means if you are using the workbench API to register a new custom craft; functions likeminetest.register_craft
,minetest.register_on_craft
,minetest.register_craft_predict
,minetest.get_craft_result
,minetest.get_craft_recipe
,minetest.get_all_craft_recipes
are NO longer usable.But who needs those when workbench itself exposes a lot more data, which you can easily use to add your own modifications directly. (See api.txt for more info) This includes;
output
- Of course, the basic outputmax_craftable
- Maximum amount of times the crafting can be donedecremented_input
- Similar tominetest.get_craft_result
result, get an inventory list of what happens to the crafting grid/input after a craft is completed (replacements
,transfer_meta
are automatically applied to this list)time
- Completely custom value, use however you likerecipe
- Reliable output of the correct recipe, minetest builtin recipe finding function just finds the closest, this is the exactreplacements
- Get all the replacements, should be redundant info because its already applied bydecremented_input
, but if you have a use for it.residue
/extra
- Extra output resultsFor future crafting registrations;
Workbench Fuel API
As noted, this current API is very basic rn, and isn't that different from what the old workbench has. For this reason, I don't suggest anyone use it yet, there will likely be major changes to it later, and I'm releasing it in its current form now because I don't think anyone would use this much for now - default fuel should suffice. For anyone that wants to use it to create custom fuel, contact me.
Showcase of API features
A new furnace and craftbench (crafting table) has been added using all these features. See
workbench/furnace.lua
andworkbench/craftbench.lua
for examples on all this features are utilized. Additionally, the tablesaw and CNC machine uses them as well, seeshapes/crafting.lua
There's an API documentation as well, seeworkbench/api/api.txt
Additionally, feel free to directly contact me on discord to explain how to use it.Other changes
transfer_meta
feature of workbench, as such its crafting recipe have been switched to workbench format.ccore.register_craftcopy
is now redundant - but I will leave it in till the inventory rework that will incorporate the new workbench crafting grid into the player inventory.TODO