Fixed listrings, orbs show charge in description
This commit is contained in:
parent
48204108c7
commit
af2404358d
|
@ -33,18 +33,19 @@ function get_element_constructor_formspec()
|
|||
mcl_formspec.get_itemslot_bg(0,5,9,3),
|
||||
"list[current_player;main;0,8.5;9,1;]",
|
||||
mcl_formspec.get_itemslot_bg(0,8.5,9,1),
|
||||
"listring[current_player;main]",
|
||||
"listring[context;src]",
|
||||
"listring[current_player;main]",
|
||||
"listring[context;fuel]",
|
||||
"listring[current_player;main]",
|
||||
"listring[context;dst]",
|
||||
"listring[current_player;main]"
|
||||
}
|
||||
return table.concat(formspec, "")
|
||||
end
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
if exchangeclone.mineclone then return true end
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("fuel") and inv:is_empty("src") and inv:is_empty("dst")
|
||||
|
@ -74,6 +75,7 @@ local function on_timer(pos, elapsed)
|
|||
end
|
||||
-- give orb new charge value
|
||||
fuel_stack:get_meta():set_int("stored_charge", orb_charge)
|
||||
fuel_stack:get_meta():set_string("description", "Current charge: "..tostring(orb_charge))
|
||||
inv:set_stack("fuel", 1, fuel_stack)
|
||||
-- "convert" charge into a node at dst
|
||||
if dst_stack:is_empty() then
|
||||
|
@ -161,19 +163,22 @@ minetest.register_node("exchangeclone:element_constructor", {
|
|||
},
|
||||
groups = {cracky = 2, container = 4},
|
||||
is_ground_content = false,
|
||||
can_dig = can_dig,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta2 = meta:to_table()
|
||||
meta:from_table(oldmetadata)
|
||||
local inv = meta:get_inventory()
|
||||
for _, listname in ipairs({"src", "dst", "fuel"}) do
|
||||
local stack = inv:get_stack(listname, 1)
|
||||
if not stack:is_empty() then
|
||||
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
end
|
||||
meta:from_table(meta2)
|
||||
if exchangeclone.mineclone then
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta2 = meta:to_table()
|
||||
meta:from_table(oldmetadata)
|
||||
local inv = meta:get_inventory()
|
||||
for _, listname in ipairs({"src", "dst", "fuel"}) do
|
||||
local stack = inv:get_stack(listname, 1)
|
||||
if not stack:is_empty() then
|
||||
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
end
|
||||
meta:from_table(meta2)
|
||||
end
|
||||
end,
|
||||
on_timer = on_timer,
|
||||
on_construct = on_construct,
|
||||
|
|
|
@ -9,10 +9,10 @@ function get_element_deconstructor_formspec()
|
|||
"label[5,1;Orb]",
|
||||
"list[context;dst;5,2;1,1;]",
|
||||
"list[current_player;main;0,5;8,4;]",
|
||||
"listring[current_player;main]",
|
||||
"listring[context;main]",
|
||||
"listring[current_player;main]",
|
||||
"listring[context;dst]",
|
||||
"listring[current_player;main]"
|
||||
"listring[context;dst]"
|
||||
}
|
||||
return table.concat(formspec, "")
|
||||
else
|
||||
|
@ -38,6 +38,7 @@ function get_element_deconstructor_formspec()
|
|||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
if exchangeclone.mineclone then return true end
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main") and inv:is_empty("dst")
|
||||
|
@ -61,6 +62,7 @@ local function on_timer(pos, elapsed)
|
|||
local stored = dest_orb:get_meta():get_int("stored_charge") or 0
|
||||
stored = stored + energy_value
|
||||
dest_orb:get_meta():set_int("stored_charge", stored)
|
||||
dest_orb:get_meta():set_string("description", "Current charge: "..tostring(stored))
|
||||
inv:set_stack("dst", 1, dest_orb)
|
||||
|
||||
update = true
|
||||
|
@ -134,18 +136,20 @@ minetest.register_node("exchangeclone:element_deconstructor", {
|
|||
groups = {cracky = 2, container = 3},
|
||||
is_ground_content = false,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta2 = meta:to_table()
|
||||
meta:from_table(oldmetadata)
|
||||
local inv = meta:get_inventory()
|
||||
for _, listname in ipairs({"main", "dst"}) do
|
||||
local stack = inv:get_stack(listname, 1)
|
||||
if not stack:is_empty() then
|
||||
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
end
|
||||
meta:from_table(meta2)
|
||||
if exchangeclone.mineclone then
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta2 = meta:to_table()
|
||||
meta:from_table(oldmetadata)
|
||||
local inv = meta:get_inventory()
|
||||
for _, listname in ipairs({"main", "dst"}) do
|
||||
local stack = inv:get_stack(listname, 1)
|
||||
if not stack:is_empty() then
|
||||
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
end
|
||||
meta:from_table(meta2)
|
||||
end
|
||||
end,
|
||||
on_timer = on_timer,
|
||||
on_construct = on_construct,
|
||||
|
|
|
@ -27,6 +27,7 @@ function get_energy_collector_formspec()
|
|||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
if exchangeclone.mineclone then return true end
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
|
@ -50,6 +51,7 @@ local function on_timer(pos, elapsed)
|
|||
local stored = dest_orb:get_meta():get_int("stored_charge") or 0
|
||||
stored = stored + 1
|
||||
dest_orb:get_meta():set_int("stored_charge", stored)
|
||||
dest_orb:get_meta():set_string("description", "Current charge: "..tostring(stored))
|
||||
inv:set_stack("main", 1, dest_orb)
|
||||
end
|
||||
return true
|
||||
|
@ -114,18 +116,20 @@ minetest.register_node("exchangeclone:energy_collector", {
|
|||
groups = {cracky = 2, container = 2},
|
||||
is_ground_content = false,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta2 = meta:to_table()
|
||||
meta:from_table(oldmetadata)
|
||||
local inv = meta:get_inventory()
|
||||
for _, listname in ipairs({"main"}) do
|
||||
local stack = inv:get_stack(listname, 1)
|
||||
if not stack:is_empty() then
|
||||
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
end
|
||||
meta:from_table(meta2)
|
||||
if exchangeclone.mineclone then
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta2 = meta:to_table()
|
||||
meta:from_table(oldmetadata)
|
||||
local inv = meta:get_inventory()
|
||||
for _, listname in ipairs({"main"}) do
|
||||
local stack = inv:get_stack(listname, 1)
|
||||
if not stack:is_empty() then
|
||||
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
end
|
||||
meta:from_table(meta2)
|
||||
end
|
||||
end,
|
||||
on_timer = on_timer,
|
||||
on_construct = on_construct,
|
||||
|
|
Loading…
Reference in New Issue