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

User avatar
Hamlet
Member
 
Posts: 631
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

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

by Hamlet » Sat Oct 07, 2017 20:52

---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.
 

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

Re: How to redefine a minetest.register_craft recipe?

by Linuxdirk » Sat Oct 07, 2017 22:10

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: 631
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: How to redefine a minetest.register_craft recipe?

by Hamlet » Sat Oct 07, 2017 23:15

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
 

User avatar
GreenDimond
Member
 
Posts: 1272
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: How to redefine a minetest.register_craft recipe?

by GreenDimond » Sat Oct 07, 2017 23:37

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},
   }
})
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenDimond#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

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

Re: How to redefine a minetest.register_craft recipe?

by Linuxdirk » Sun Oct 08, 2017 08:27

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: 631
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: How to redefine a minetest.register_craft recipe?

by Hamlet » Sun Oct 08, 2017 08:29

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.
 

User avatar
Hamlet
Member
 
Posts: 631
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: How to redefine a minetest.register_craft recipe?

by Hamlet » Sun Oct 08, 2017 08:40

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.
 

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

Re: How to redefine a minetest.register_craft recipe?

by Linuxdirk » Sun Oct 08, 2017 10:35

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: 2201
Joined: Sun Apr 09, 2017 05:50
Location: Hopefully very far from yours, snoop :P
GitHub: LoneWolfHT
IRC: Lone_Wolf
In-game: Lone_Wolf

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

by Lone_Wolf » Tue Oct 17, 2017 03:33

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"})
 

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

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

by Linuxdirk » Tue Oct 17, 2017 05:27

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.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 11 guests