[Solved] How to redefine a minetest.register_craft recipe?

Post Reply
User avatar
Hamlet
Member
Posts: 766
Joined: Sat Jul 29, 2017 21:09
IRC: H4mlet
In-game: Hamlet
Location: Lombardy, Italy

[Solved] How to redefine a minetest.register_craft recipe?

by Hamlet » Post

---2nd edit begin

Thanks to GreenDimond and Linuxdirk, the correct method is:

To remove the old recipe:

Code: Select all

minetest.clear_craft({output = "mod_name:node_name"})
To create a new one:

Code: Select all

minetest.register_craft({
   output = "mod_name:node_name",
   recipe = {
      {new recipe},
   }
})
---2nd edit end

Example of the recipe to be redefined:

Code: Select all

minetest.register_craft({
   output = "mod_name:node_name",
   recipe = {
      {"default:dirt", "default:stone",},
   }
})
Example of how I am trying to redefine it:

Code: Select all

minetest.override_item("mod_name:node_name", {
   recipe = {
      {"default:gold", "default:silver",},
   }
})
---EDIT: Just to make it clear (if it wasn't already), it doesn't work.

From the lua_api.txt (v0.4.16):

--- quote start
* `minetest.override_item(name, redefinition)`
* Overrides fields of an item registered with register_node/tool/craftitem.
* Note: Item must already be defined, (opt)depend on the mod defining it.
* Example: `minetest.override_item("default:mese", {light_source=LIGHT_MAX})`
--- quote end

Given that the registration method isn't register_node/tool/craftitem, it isn't possible to redefine such a recipe using minetest.override_item; if I have understood it correctly.

Any hints/help please?
Last edited by Hamlet on Sun Oct 08, 2017 09:01, edited 2 times in total.
My repositories: Codeberg.org | My ContentDB's page

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to redefine a minetest.register_craft recipe?

by Linuxdirk » Post

If it is a registered node, tool, or craftitem you can overrride it as shown in the documentation using minetest.override_item(). As stated in the documentation the thing has to be registered already. Since the function does not care HOW the thing was registered it is just important THAT the thing was registered.

OT: Registering things in Minetest not using the designated API function for that is stupid and should be avoided.

User avatar
Hamlet
Member
Posts: 766
Joined: Sat Jul 29, 2017 21:09
IRC: H4mlet
In-game: Hamlet
Location: Lombardy, Italy

Re: How to redefine a minetest.register_craft recipe?

by Hamlet » Post

Linuxdirk wrote:If it is a registered node, tool, or craftitem you can overrride it as shown in the documentation using minetest.override_item(). As stated in the documentation the thing has to be registered already. Since the function does not care HOW the thing was registered it is just important THAT the thing was registered.

OT: Registering things in Minetest not using the designated API function for that is stupid and should be avoided.
Out of curiosity, have you read my post's contents before replying or have you read just the title?
Just for the record (in reply to the OT): http://dev.minetest.net/minetest.register_craft
My repositories: Codeberg.org | My ContentDB's page

User avatar
GreenXenith
Member
Posts: 1356
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
Location: UTC-8:00
Contact:

Re: How to redefine a minetest.register_craft recipe?

by GreenXenith » Post

This is the way I do it, though I have no idea if this is the best way.

Code: Select all

minetest.register_craft({
   output = "mod_name:node_name 0",
   recipe = {
      {original recipe},
   }
})
(note the 0 in the output)
and then

Code: Select all

minetest.register_craft({
   output = "mod_name:node_name",
   recipe = {
      {new recipe},
   }
})
YouTube | Mods | Patreon | Minetest Discord @greenxenith

You should not be able to read this message.

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to redefine a minetest.register_craft recipe?

by Linuxdirk » Post

Hamlet wrote:Out of curiosity, have you read my post's contents before replying or have you read just the title?
You mean before you edited it to clarify what the actual issue is? Your English and your posting style make it hard to understand what you actually want.

As far as I understand you want to alter a craft recipe.

The intended way of doing this is first deleting the craft recipe and then registering a new one.

http://dev.minetest.net/minetest.clear_craft
http://dev.minetest.net/minetest.register_craft

User avatar
Hamlet
Member
Posts: 766
Joined: Sat Jul 29, 2017 21:09
IRC: H4mlet
In-game: Hamlet
Location: Lombardy, Italy

Re: How to redefine a minetest.register_craft recipe?

by Hamlet » Post

GreenDimond wrote:This is the way I do it, though I have no idea if this is the best way. [snip]
It works nicely!
Go figure that I had thought about that method but immediately discarded the idea 'cause I thought that would have registered an alternative recipe for the same item, when it actually just redefines it.

This tells a lot about wrong assumptions!

Thanks for your help, you've saved a lot of my time since I need to tweak some mods' recipes for my subgame - manually modifying them isn't exactly the best way.
My repositories: Codeberg.org | My ContentDB's page

User avatar
Hamlet
Member
Posts: 766
Joined: Sat Jul 29, 2017 21:09
IRC: H4mlet
In-game: Hamlet
Location: Lombardy, Italy

Re: How to redefine a minetest.register_craft recipe?

by Hamlet » Post

Linuxdirk wrote:You mean before you edited it to clarify what the actual issue is? Your English and your posting style make it hard to understand what you actually want.
Do you mean that by simply adding
"---EDIT: Just to make it clear (if it wasn't already), it doesn't work."
my whole post has become intelligible? Impressive.
Linuxdirk wrote: As far as I understand you want to alter a craft recipe.

The intended way of doing this is first deleting the craft recipe and then registering a new one.

http://dev.minetest.net/minetest.clear_craft
http://dev.minetest.net/minetest.register_craft
Brilliant, this is indeed the best way; GreenDimond's method works but I guess that if there is a "minetest.clear_craft" probably it's better to remove the old crafting recipe and then register a new one instead of forcing a new recipe for the same item - just to be double sure.

Thanks for your help, this will ensure that no possible side-effect glitches will happen.
My repositories: Codeberg.org | My ContentDB's page

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to redefine a minetest.register_craft recipe?

by Linuxdirk » Post

Hamlet wrote:but I guess that if there is a "minetest.clear_craft" probably it's better to remove the old crafting recipe and then register a new one instead of forcing a new recipe for the same item - just to be double sure.
Yes, feels much cleaner than overriding the item definition.

User avatar
Lone_Wolf
Member
Posts: 2578
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [Solved] How to redefine a minetest.register_craft recip

by Lone_Wolf » Post

minetest.clear_craft({output = "mod_name:node_name"})

This works for tool and craftitem recipes too?
EDIT:
Assuming you just change

Code: Select all

minetest.clear_craft({output = "mod_name:name"})
to

Code: Select all

minetest.clear_craftitem({output = "mod_name:name"})
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Solved] How to redefine a minetest.register_craft recip

by Linuxdirk » Post

Lone_Wolf wrote:This works for tool and craftitem recipes too?
The name is a bit misleading. You can delete whatever you want that is identified by the provided definition.

Beware: Deletion by recipe is extremely slow.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests