Need help for mod
Mahlzeit!
I try to code my own mod for minetest. Some friends and I play Minetest on a private server and now I try to build mods for us. Maybe in futur for public release if I think its stabel and someone are interestet.
My first problem, I craft an new node and if I put them on the ground I can open it like a furnace oder cest ore something like that. I become an Inventory with some seperated lists like src, fuel and player inventory and a field for some input.
Now the input in the field shoud me saved in the node so I can use it, change it usw. Nothing I can do to save the entry. I try it like the sign in default but nothing. Whats the problem?
Here is the code:
I try to code my own mod for minetest. Some friends and I play Minetest on a private server and now I try to build mods for us. Maybe in futur for public release if I think its stabel and someone are interestet.
My first problem, I craft an new node and if I put them on the ground I can open it like a furnace oder cest ore something like that. I become an Inventory with some seperated lists like src, fuel and player inventory and a field for some input.
Now the input in the field shoud me saved in the node so I can use it, change it usw. Nothing I can do to save the entry. I try it like the sign in default but nothing. Whats the problem?
Here is the code:
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
local bauer_inactive_formspec =
"size[8,9]"..
"label[1,0;Baumaterial]"..
"label[1,2;Treibstoff]"..
"field[4,1;4,3;terminal;Terminal;${text}]"..
"list[current_name;fuel;2,3;1,1;]"..
"list[current_name;src;2,1;1,1;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("diabolus:helfer_bauer", {
description = "Bauarbeiter",
tiles = {"helfer_bauer.png"},
walkable = true,
light_source = 10,
groups = {cracky=2, flammable=3},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", bauer_inactive_formspec)
meta:set_string("infotext", "Hornbach")
local inv = meta:get_inventory()
inv:set_size("fuel", 1)
inv:set_size("src", 1)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("fuel") then
return false
elseif not inv:is_empty("src") then
return false
end
return true
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
meta:set_string("text", fields.text)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if listname == "fuel" then
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
if inv:is_empty("src") then
meta:set_string("infotext","Hornbach ist leer")
end
return stack:get_count()
else
return 0
end
elseif listname == "src" then
return stack:get_count()
end
end,
})