Muuus wrote:Hi there,
I'm new to Minetest and the world of modding, trying to get a grasp over things like formspec, I started creating a mod with a mixer utilitary block, adding new kind of recipes, based on the furnace. I'm basing that on the furnace, so I want a similar GUI, but with a water drop in place of the fire and two slots for src instead of only one. Also, I want to use 'liquid' instead of 'fuel', like putting a water bucket inside the mixer in the 'liquid (ex-'fuel') slot, and then transforming sand and gravel in the src slots into a new block like concrete.
What I'm asking myself, is if it's possible to do that without touching the .cpp files, but only as LUA mod ? I mean, I saw that some of the variable like fuel_totaltime or fuel_time are also used in some .cpp file, so I was wondering if I could do something similar to the furnace_node_timer function for my mixer, without touching the Minetest engine and the .cpp/.h files ?
Sorry if I couldn't make myself clear enough, hope you can help me on that one.
Have a look at /games/minetest_game/default/furnace.lua and try to figure out how it works there, then do your modifications.
I'll explain the concepts of formspecs to you:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
"size[8,8.5]"..
"list[current_name;src;2.75,0.5;1,1;]"..
"list[current_name;fuel;2.75,2.5;1,1;]"..
"image[2.75,1.5;1,1;default_furnace_fire_bg.png]"..
"image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
"list[current_name;dst;4.75,0.96;2,2;]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"listring[current_name;dst]"..
"listring[current_player;main]"..
"listring[current_name;src]"..
"listring[current_player;main]"
This is a typical formspec definition. It's just one long string, the quotes and concat dots (..) are just for better readability, because you can't insert newlines in lua strings*. It defines the entire GUI for an inactive furnace. For example, image[...] draws an image at this screen position and list[...] shows an inventory list (or a single slot).
See the lua_api.txt section "Formspecs" for details on what works how.
'doc/lua_api.txt' will help you in a lot of places.
Furnace 'on_construct' callback:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
on_construct = function(pos)
--get the metadata of the node (a key-value-store and an inventory)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", inactive_formspec)
--you can put any data into the metadata, like percentage of items processed. See "NodeMetaRef"
--but the key 'formspec' is reserved for the formspec to be show when the node is right-clicked.
local inv = meta:get_inventory()
--get the node's inventory and set the sizes of the inventory list. See lua_api.txt section "InvRef"
inv:set_size('src', 1)
inv:set_size('fuel', 1)
inv:set_size('dst', 4)
end,
On fuel stuff in cpp files: irrelevant. Possibly for compatibility with very old minetest worlds...
* you can by using [[this string
has newlines
in it.]], but this does not look pretty.