mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-08-18 20:04:04 +02:00
make constructed controllers pick-uppable
This commit is contained in:
parent
27c9d82ea4
commit
9d526997fc
@ -23,7 +23,7 @@ local get_controller_unconstructed_formspec = function(pos, player_name)
|
|||||||
return "size[9,9]"
|
return "size[9,9]"
|
||||||
.. "container[0.5,0]"
|
.. "container[0.5,0]"
|
||||||
.. "button[0,0;1,1;construct;Construct]"
|
.. "button[0,0;1,1;construct;Construct]"
|
||||||
.. "field[1.2,0.25;2,1;digtron_name;Digtron name;"..meta:get_string("digtron_name").."]"
|
.. "field[1.2,0.25;2,1;digtron_name;Digtron name;"..meta:get_string("infotext").."]"
|
||||||
.. "field_close_on_enter[digtron_name;false]"
|
.. "field_close_on_enter[digtron_name;false]"
|
||||||
.. "container_end[]"
|
.. "container_end[]"
|
||||||
end
|
end
|
||||||
@ -70,10 +70,49 @@ minetest.register_node("digtron:controller", {
|
|||||||
|
|
||||||
on_dig = function(pos, node, digger)
|
on_dig = function(pos, node, digger)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if meta:get_string("digtron_id") ~= "" then
|
local digtron_id = meta:get_string("digtron_id")
|
||||||
return -- TODO: special handling here!
|
|
||||||
else
|
local stack = ItemStack({name=node.name, count=1, wear=0})
|
||||||
return minetest.node_dig(pos, node, digger)
|
local stack_meta = stack:get_meta()
|
||||||
|
stack_meta:set_string("digtron_id", digtron_id)
|
||||||
|
stack_meta:set_string("description", meta:get_string("infotext"))
|
||||||
|
local inv = digger:get_inventory()
|
||||||
|
local stack = inv:add_item("main", stack)
|
||||||
|
if stack:get_count() > 0 then
|
||||||
|
minetest.add_item(pos, stack)
|
||||||
|
end
|
||||||
|
-- call on_dignodes callback
|
||||||
|
minetest.remove_node(pos)
|
||||||
|
|
||||||
|
if digtron_id ~= "" then
|
||||||
|
-- TODO destroy other nodes belonging to this digtron
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
--TODO: this didn't work when I blew up the digtron with TNT, investigate why
|
||||||
|
preserve_metadata = function(pos, oldnode, oldmeta, drops)
|
||||||
|
for _, dropped in ipairs(drops) do
|
||||||
|
if dropped:get_name() == "digtron:controller" then
|
||||||
|
local stack_meta = dropped:get_meta()
|
||||||
|
stack_meta:set_string("digtron_id", oldmeta:get_string("digtron_id"))
|
||||||
|
stack_meta:set_string("description", oldmeta:get_string("infotext"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
|
local stack_meta = itemstack:get_meta()
|
||||||
|
local title = stack_meta:get_string("description")
|
||||||
|
local digtron_id = stack_meta:get_string("digtron_id")
|
||||||
|
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
|
meta:set_string("infotext", title)
|
||||||
|
meta:set_string("digtron_id", digtron_id)
|
||||||
|
|
||||||
|
if digtron_id ~= "" then
|
||||||
|
-- TODO create the other nodes belonging to this digtron
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -126,7 +165,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
|
|
||||||
if fields.key_enter_field == "digtron_name" or fields.digtron_name then
|
if fields.key_enter_field == "digtron_name" or fields.digtron_name then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("digtron_name", fields.digtron_name)
|
meta:set_string("infotext", fields.digtron_name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -164,6 +203,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if fields.key_enter_field == "digtron_name" or fields.digtron_name then
|
if fields.key_enter_field == "digtron_name" or fields.digtron_name then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("infotext", fields.digtron_name)
|
||||||
digtron.set_name(digtron_id, fields.digtron_name)
|
digtron.set_name(digtron_id, fields.digtron_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ digtron.construct = function(root_pos, player_name)
|
|||||||
layout[relative_hash] = {meta = current_meta_table, node = node}
|
layout[relative_hash] = {meta = current_meta_table, node = node}
|
||||||
end
|
end
|
||||||
|
|
||||||
digtron.set_name(digtron_id, root_meta:get_string("digtron_name"))
|
digtron.set_name(digtron_id, root_meta:get_string("infotext"))
|
||||||
persist_inventory(digtron_id)
|
persist_inventory(digtron_id)
|
||||||
persist_layout(digtron_id, layout)
|
persist_layout(digtron_id, layout)
|
||||||
persist_adjacent(digtron_id, digtron_adjacent)
|
persist_adjacent(digtron_id, digtron_adjacent)
|
||||||
@ -313,7 +313,7 @@ end
|
|||||||
|
|
||||||
digtron.deconstruct = function(digtron_id, root_pos, name)
|
digtron.deconstruct = function(digtron_id, root_pos, name)
|
||||||
local root_meta = minetest.get_meta(root_pos)
|
local root_meta = minetest.get_meta(root_pos)
|
||||||
root_meta:set_string("digtron_name", digtron.get_name(digtron_id))
|
root_meta:set_string("infotext", digtron.get_name(digtron_id))
|
||||||
|
|
||||||
local layout = retrieve_layout(digtron_id)
|
local layout = retrieve_layout(digtron_id)
|
||||||
local inv = digtron.retrieve_inventory(digtron_id)
|
local inv = digtron.retrieve_inventory(digtron_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user