Add pack controller
This commit is contained in:
parent
93ce219eec
commit
bec48ca37f
@ -300,6 +300,7 @@ end
|
|||||||
-- on_transfer = func(pos, in_dir, topic, payload),
|
-- on_transfer = func(pos, in_dir, topic, payload),
|
||||||
-- }
|
-- }
|
||||||
function techage.register_node(names, node_definition)
|
function techage.register_node(names, node_definition)
|
||||||
|
node_definition = node_definition or {}
|
||||||
-- store facedir table for all known node names
|
-- store facedir table for all known node names
|
||||||
for _,n in ipairs(names) do
|
for _,n in ipairs(names) do
|
||||||
NodeDef[n] = node_definition
|
NodeDef[n] = node_definition
|
||||||
|
@ -151,6 +151,18 @@ function techage.get_nvm(pos)
|
|||||||
return block[key2]
|
return block[key2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns true/false
|
||||||
|
function techage.has_nvm(pos)
|
||||||
|
local key1, key2 = get_keys(pos)
|
||||||
|
|
||||||
|
if not NvmStore[key1] then
|
||||||
|
NvmStore[key1] = backend.get_mapblock_data(key1)
|
||||||
|
push(key1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return NvmStore[key1][key2] ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
function techage.peek_nvm(pos)
|
function techage.peek_nvm(pos)
|
||||||
local key1, key2 = get_keys(pos)
|
local key1, key2 = get_keys(pos)
|
||||||
local block = NvmStore[key1] or {}
|
local block = NvmStore[key1] or {}
|
||||||
|
@ -13,50 +13,104 @@
|
|||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- for lazy programmers
|
-- for lazy programmers
|
||||||
local P = minetest.string_to_pos
|
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
|
|
||||||
--function techage.pack_nvm(pos)
|
-- string/usercode conversion
|
||||||
-- return minetest.serialize(techage.)
|
local function usercode_to_string(tbl)
|
||||||
--end
|
if tbl and tbl.inventory then
|
||||||
|
for list_name,list in pairs(tbl.inventory) do
|
||||||
|
for i,item in ipairs(list) do
|
||||||
|
tbl.inventory[list_name][i] = item:to_string()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--function techage.unpack_nvm(pos)
|
local function string_to_usercode(tbl)
|
||||||
--end
|
if tbl and tbl.inventory then
|
||||||
|
for list_name,list in pairs(tbl.inventory) do
|
||||||
|
for i,item in ipairs(list) do
|
||||||
|
tbl.inventory[list_name][i] = ItemStack(item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function serialize_inventory(tbl)
|
-- pack/unpack node nvm data
|
||||||
local out1 = {}
|
function techage.pack_nvm(pos)
|
||||||
|
if techage.has_nvm(pos) then
|
||||||
|
local s = minetest.serialize(techage.get_nvm(pos))
|
||||||
|
techage.del_mem(pos)
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function techage.unpack_nvm(pos, s)
|
||||||
|
local tbl = minetest.deserialize(s)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
for k,v in pairs(tbl) do
|
for k,v in pairs(tbl) do
|
||||||
local out2 = {}
|
nvm.k = v
|
||||||
for i,item in ipairs(v) do
|
|
||||||
out2[i] = item:to_string()
|
|
||||||
end
|
end
|
||||||
out1[k] = minetest.serialize(out2)
|
|
||||||
end
|
|
||||||
return out1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- pack/unpack node metedata
|
||||||
function techage.pack_meta(pos)
|
function techage.pack_meta(pos)
|
||||||
local tbl = M(pos):to_table()
|
local tbl = M(pos):to_table() or {}
|
||||||
local fields, inventory
|
usercode_to_string(tbl)
|
||||||
|
return minetest.serialize(tbl)
|
||||||
if tbl and tbl.fields then
|
|
||||||
fields = minetest.serialize(tbl.fields)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local inv = minetest.get_inventory({type="node", pos=pos})
|
function techage.unpack_meta(pos, s)
|
||||||
local lists = inv:get_lists()
|
local tbl = minetest.deserialize(s) or {}
|
||||||
print(dump(lists))
|
string_to_usercode(tbl)
|
||||||
if lists then
|
M(pos):from_table(tbl)
|
||||||
inventory = serialize_inventory(lists)
|
|
||||||
end
|
|
||||||
return minetest.serialize({fields = fields, inventory = inventory})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--function techage.unpack_meta(pos, s)
|
-- on_pack/on_unpack fallback functions
|
||||||
-- local tbl = minetest.deserialize(s or "") or {}
|
local function on_pack_fallback_(pos, node)
|
||||||
-- local out = {}
|
print("on_pack_fallback_",P2S(pos), node.name)
|
||||||
-- for i,item in ipairs(tbl) do
|
local smeta = techage.pack_meta(pos)
|
||||||
-- out[i] = ItemStack(item)
|
local snvm = techage.pack_nvm(pos)
|
||||||
-- end
|
minetest.remove_node(pos)
|
||||||
-- local inv = minetest.get_inventory({type="node", pos=pos})
|
return {smeta = smeta, snvm = snvm}
|
||||||
--end
|
end
|
||||||
|
|
||||||
|
local function on_unpack_fallback(pos, name, param2, data)
|
||||||
|
print("on_unpack_fallback",P2S(pos), name)
|
||||||
|
minetest.add_node(pos, {name = name, param2 = param2})
|
||||||
|
techage.unpack_meta(pos, data.smeta)
|
||||||
|
if data.snvm then
|
||||||
|
techage.unpack_nvm(pos, data.snvm)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- pack/unpack API functions
|
||||||
|
function techage.pack_nodes(pos, pos_list)
|
||||||
|
print("pack_nodes", P2S(pos), #pos_list)
|
||||||
|
local tbl = {}
|
||||||
|
for idx, rpos in ipairs(pos_list or {}) do
|
||||||
|
local pos2 = vector.add(pos, rpos)
|
||||||
|
local node = minetest.get_node(pos2)
|
||||||
|
--print("node", node.name, P2S(pos))
|
||||||
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
|
if ndef and ndef.on_pack then
|
||||||
|
tbl[rpos] = {name = node.name, param2 = node.param2, data = ndef.on_pack(pos2, node)}
|
||||||
|
else
|
||||||
|
tbl[rpos] = {name = node.name, param2 = node.param2, data = on_pack_fallback_(pos2, node)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
|
function techage.unpack_nodes(pos, tbl)
|
||||||
|
for rpos, item in pairs(tbl or {}) do
|
||||||
|
local pos2 = vector.add(pos, rpos)
|
||||||
|
local ndef = minetest.registered_nodes[item.name]
|
||||||
|
if ndef and ndef.on_unpack then
|
||||||
|
ndef.on_unpack(pos2, item.name, item.param2, item.data)
|
||||||
|
else
|
||||||
|
on_unpack_fallback(pos2, item.name, item.param2, item.data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
7
init.lua
7
init.lua
@ -307,11 +307,11 @@ dofile(MP.."/move_controller/movecontroller.lua")
|
|||||||
dofile(MP.."/move_controller/turncontroller.lua")
|
dofile(MP.."/move_controller/turncontroller.lua")
|
||||||
dofile(MP.."/move_controller/flycontroller.lua")
|
dofile(MP.."/move_controller/flycontroller.lua")
|
||||||
dofile(MP.."/move_controller/soundblock.lua")
|
dofile(MP.."/move_controller/soundblock.lua")
|
||||||
|
dofile(MP.."/move_controller/packcontainer.lua")
|
||||||
|
|
||||||
-- Test
|
-- Test
|
||||||
dofile(MP.."/recipe_checker.lua")
|
dofile(MP.."/recipe_checker.lua")
|
||||||
dofile(MP.."/.test/sink.lua")
|
--dofile(MP.."/.test/sink.lua")
|
||||||
|
|
||||||
-- Solar
|
-- Solar
|
||||||
dofile(MP.."/solar/minicell.lua")
|
dofile(MP.."/solar/minicell.lua")
|
||||||
@ -415,6 +415,3 @@ dofile(MP.."/fusion_reactor/ta5_pump.lua")
|
|||||||
|
|
||||||
-- Prevent other mods from using IE
|
-- Prevent other mods from using IE
|
||||||
techage.IE = nil
|
techage.IE = nil
|
||||||
|
|
||||||
|
|
||||||
function techage.icta_register_condition(key, tData) end
|
|
||||||
|
@ -28,36 +28,73 @@ local DESCRIPTION = S("TA5 Pack Container")
|
|||||||
local function formspec(nvm, meta)
|
local function formspec(nvm, meta)
|
||||||
local status = meta:get_string("status")
|
local status = meta:get_string("status")
|
||||||
local path = meta:contains("path") and meta:get_string("path") or "0,3,0"
|
local path = meta:contains("path") and meta:get_string("path") or "0,3,0"
|
||||||
return "size[8,3]" ..
|
local node_name = meta:get_string("node_name")
|
||||||
|
return "size[8,4.3]" ..
|
||||||
"box[0,-0.1;7.8,0.5;#c6e8ff]" ..
|
"box[0,-0.1;7.8,0.5;#c6e8ff]" ..
|
||||||
"label[0.2,-0.1;" .. minetest.colorize( "#000000", DESCRIPTION) .. "]" ..
|
"label[0.2,-0.1;" .. minetest.colorize( "#000000", DESCRIPTION) .. "]" ..
|
||||||
--techage.wrench_image(7.4, -0.05) ..
|
--techage.wrench_image(7.4, -0.05) ..
|
||||||
"button[0.1,0.7;3.8,1;record;" .. S("Record") .. "]" ..
|
"field[0.4,1.2;3.8,1;node_name;" .. S("Node name") .. ";" .. node_name .. "]" ..
|
||||||
"button[4.1,0.7;3.8,1;done;" .. S("Done") .. "]" ..
|
"button[4.1,0.9;3.8,1;store;" .. S("Store") .. "]" ..
|
||||||
"button[0.1,1.5;3.8,1;left;" .. S("Turn left") .. "]" ..
|
"button[0.1,2.1;3.8,1;record;" .. S("Record") .. "]" ..
|
||||||
"button[4.1,1.5;3.8,1;right;" .. S("Turn right") .. "]" ..
|
"box[0,1.9;7.8,0.02;#ffffff]" ..
|
||||||
"label[0.3,2.5;" .. status .. "]"
|
"button[4.1,2.1;3.8,1;done;" .. S("Done") .. "]" ..
|
||||||
|
"button[0.1,2.9;3.8,1;pack;" .. S("Pack") .. "]" ..
|
||||||
|
"button[4.1,2.9;3.8,1;unpack;" .. S("Unpack") .. "]" ..
|
||||||
|
"label[0.3,9;" .. status .. "]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_rposlist(pos, pos_list)
|
||||||
|
local lst = {}
|
||||||
|
for _,item_pos in ipairs(pos_list or {}) do
|
||||||
|
local rpos = vector.subtract(item_pos, pos)
|
||||||
|
table.insert(lst, rpos)
|
||||||
|
end
|
||||||
|
return lst
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("techage:ta4_turncontroller", {
|
local function set_storage_pos(pos, oldnode, oldmetadata, drops)
|
||||||
description = S("TA4 Turn Controller"),
|
local meta = drops[1]:get_meta()
|
||||||
tiles = {
|
meta:set_string("storage_pos", P2S(pos))
|
||||||
-- up, down, right, left, back, front
|
meta:set_string("node_name", (oldmetadata.node_name or ""))
|
||||||
"techage_filling_ta4.png^techage_frame_ta4_top.png",
|
meta:set_string("description", DESCRIPTION .. ' "' .. (oldmetadata.node_name or "") .. '"')
|
||||||
"techage_filling_ta4.png^techage_frame_ta4_top.png",
|
end
|
||||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_turn.png",
|
|
||||||
},
|
|
||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack)
|
local function get_storage_pos(pos, nvm, itemstack)
|
||||||
|
print("get_storage_pos")
|
||||||
|
local imeta = itemstack:get_meta()
|
||||||
|
if imeta then
|
||||||
|
print("get_storage_pos2")
|
||||||
local meta = M(pos)
|
local meta = M(pos)
|
||||||
techage.logic.after_place_node(pos, placer, "techage:ta4_turncontroller", S("TA4 Turn Controller"))
|
meta:set_string("node_name", imeta:get_string("node_name"))
|
||||||
techage.logic.infotext(meta, DESCRIPTION)
|
nvm.storage_pos = S2P(imeta:get_string("storage_pos"))
|
||||||
local nvm = techage.get_nvm(pos)
|
print("get_storage_pos3", dump(nvm))
|
||||||
meta:set_string("formspec", formspec(nvm, meta))
|
return nvm.storage_pos ~= nil
|
||||||
end,
|
end
|
||||||
|
end
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, player)
|
local function copy_data_and_remove_node(mypos, rmtpos)
|
||||||
|
local nvm1 = techage.get_nvm(mypos)
|
||||||
|
local nvm2 = techage.get_nvm(rmtpos)
|
||||||
|
nvm1.lrpos = nvm2.lrpos
|
||||||
|
nvm1.pack_tbl = nvm2.pack_tbl
|
||||||
|
minetest.remove_node(rmtpos)
|
||||||
|
techage.del_mem(rmtpos)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function after_place_node(pos, placer, itemstack)
|
||||||
|
local meta = M(pos)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
meta:set_string("infotext", DESCRIPTION)
|
||||||
|
if get_storage_pos(pos, nvm, itemstack) then
|
||||||
|
if techage.get_node_lvm(nvm.storage_pos).name == "techage:ta5_packcontainer_storage" then
|
||||||
|
copy_data_and_remove_node(pos, nvm.storage_pos)
|
||||||
|
nvm.storage_pos = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
meta:set_string("formspec", formspec(nvm, meta))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_receive_fields(pos, formname, fields, player)
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
if minetest.is_protected(pos, player:get_player_name()) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -66,50 +103,66 @@ minetest.register_node("techage:ta4_turncontroller", {
|
|||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
|
||||||
if fields.record then
|
if fields.record then
|
||||||
nvm.lpos1 = {}
|
nvm.lrpos = {}
|
||||||
nvm.lpos2 = {}
|
|
||||||
meta:set_string("status", S("Recording..."))
|
meta:set_string("status", S("Recording..."))
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
minetest.chat_send_player(name, S("Click on all blocks that shall be turned"))
|
minetest.chat_send_player(name, S("Click on all blocks that shall be turned"))
|
||||||
mark.start(name, MAX_BLOCKS)
|
mark.start(name, MAX_BLOCKS)
|
||||||
meta:set_string("formspec", formspec(nvm, meta))
|
meta:set_string("formspec", formspec(nvm, meta))
|
||||||
|
elseif fields.store then
|
||||||
|
meta:set_string("node_name", fields.node_name)
|
||||||
|
meta:set_string("formspec", formspec(nvm, meta))
|
||||||
elseif fields.done then
|
elseif fields.done then
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local pos_list = mark.get_poslist(name)
|
local pos_list = mark.get_poslist(name)
|
||||||
local text = #pos_list.." "..S("block positions are stored.")
|
local text = #pos_list.." "..S("block positions are stored.")
|
||||||
meta:set_string("status", text)
|
meta:set_string("status", text)
|
||||||
nvm.lpos = pos_list
|
meta:set_string("node_name", fields.node_name)
|
||||||
|
nvm.lrpos = get_rposlist(pos, pos_list)
|
||||||
mark.unmark_all(name)
|
mark.unmark_all(name)
|
||||||
mark.stop(name)
|
mark.stop(name)
|
||||||
meta:set_string("formspec", formspec(nvm, meta))
|
meta:set_string("formspec", formspec(nvm, meta))
|
||||||
elseif fields.left then
|
elseif fields.pack then
|
||||||
meta:set_string("status", "")
|
nvm.pack_tbl = techage.pack_nodes(pos, nvm.lrpos or {})
|
||||||
local new_posses = fly.rotate_nodes(pos, nvm.lpos, "l")
|
meta:set_string("status", S("Packed"))
|
||||||
if new_posses then
|
meta:set_string("formspec", formspec(nvm, meta))
|
||||||
nvm.lpos = new_posses
|
meta:set_int("data_stored", 1)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
mark.stop(name)
|
||||||
|
elseif fields.unpack then
|
||||||
|
techage.unpack_nodes(pos, nvm.pack_tbl)
|
||||||
|
meta:set_string("status", S("Unpacked"))
|
||||||
|
meta:set_string("formspec", formspec(nvm, meta))
|
||||||
|
meta:set_int("data_stored", 0)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
mark.stop(name)
|
mark.stop(name)
|
||||||
end
|
end
|
||||||
meta:set_string("formspec", formspec(nvm, meta))
|
|
||||||
elseif fields.right then
|
|
||||||
meta:set_string("status", "")
|
|
||||||
local new_posses = fly.rotate_nodes(pos, nvm.lpos, "r")
|
|
||||||
if new_posses then
|
|
||||||
nvm.lpos = new_posses
|
|
||||||
local name = player:get_player_name()
|
|
||||||
mark.stop(name)
|
|
||||||
end
|
end
|
||||||
meta:set_string("formspec", formspec(nvm, meta))
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||||
local name = digger:get_player_name()
|
local name = digger:get_player_name()
|
||||||
mark.unmark_all(name)
|
mark.unmark_all(name)
|
||||||
mark.stop(name)
|
mark.stop(name)
|
||||||
techage.remove_node(pos, oldnode, oldmetadata)
|
|
||||||
end,
|
|
||||||
|
|
||||||
|
if oldmetadata.fields.data_stored == "1" then
|
||||||
|
minetest.set_node(pos, {name = "techage:ta5_packcontainer_storage"})
|
||||||
|
else
|
||||||
|
techage.del_mem(pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_node("techage:ta5_packcontainer", {
|
||||||
|
description = DESCRIPTION,
|
||||||
|
tiles = {
|
||||||
|
-- up, down, right, left, back, front
|
||||||
|
"techage_filling_ta4.png^techage_frame_ta5_top.png",
|
||||||
|
"techage_filling_ta4.png^techage_frame_ta5_top.png",
|
||||||
|
"techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_turn.png",
|
||||||
|
},
|
||||||
|
after_place_node = after_place_node,
|
||||||
|
on_receive_fields = on_receive_fields,
|
||||||
|
after_dig_node = after_dig_node,
|
||||||
|
preserve_metadata = set_storage_pos,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {choppy=2, cracky=2, crumbly=2},
|
groups = {choppy=2, cracky=2, crumbly=2},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
@ -118,38 +171,10 @@ minetest.register_node("techage:ta4_turncontroller", {
|
|||||||
|
|
||||||
local INFO = [[Commands: 'left', 'right', 'uturn']]
|
local INFO = [[Commands: 'left', 'right', 'uturn']]
|
||||||
|
|
||||||
techage.register_node({"techage:ta4_turncontroller"}, {
|
techage.register_node({"techage:ta5_packcontainer"}, {
|
||||||
on_recv_message = function(pos, src, topic, payload)
|
on_recv_message = function(pos, src, topic, payload)
|
||||||
if topic == "info" then
|
if topic == "info" then
|
||||||
return INFO
|
return INFO
|
||||||
elseif topic == "left" then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local new_posses = fly.rotate_nodes(pos, nvm.lpos, "l")
|
|
||||||
if new_posses then
|
|
||||||
nvm.lpos = new_posses
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
elseif topic == "right" then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local new_posses = fly.rotate_nodes(pos, nvm.lpos, "r")
|
|
||||||
if new_posses then
|
|
||||||
nvm.lpos = new_posses
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
elseif topic == "uturn" then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local new_posses = fly.rotate_nodes(pos, nvm.lpos, "r")
|
|
||||||
if new_posses then
|
|
||||||
nvm.lpos = new_posses
|
|
||||||
new_posses = fly.rotate_nodes(pos, nvm.lpos, "r")
|
|
||||||
if new_posses then
|
|
||||||
nvm.lpos = new_posses
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
@ -164,168 +189,34 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_node("techage:ta5_packcontainer_storage", {
|
||||||
local storage = minetest.get_mod_storage()
|
description = DESCRIPTION,
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = {
|
||||||
local function get_number()
|
type = "fixed",
|
||||||
storage:set_int("number", storage:get_int("number") + 1)
|
fixed = {
|
||||||
return storage:get_int("number")
|
{ -11/32, -1/2, -11/32, 11/32, -5/16, 11/32},
|
||||||
end
|
|
||||||
|
|
||||||
local function store_node_data(meta, lrpos, data)
|
|
||||||
local number = meta:get_string("number")
|
|
||||||
local tbl = {lrpos = lrpos, data = data}
|
|
||||||
storage:set_string(number, minetest.serialize(tbl))
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_node_data(meta)
|
|
||||||
local number = meta:get_string("number")
|
|
||||||
local s = storage:get_string(number)
|
|
||||||
storage:set_string(number, "")
|
|
||||||
local tbl = minetest.deserialize(s or "")
|
|
||||||
if tbl then
|
|
||||||
return tbl.lrpos, tbl.data
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function has_node_data(meta)
|
|
||||||
local number = meta:get_string("number")
|
|
||||||
return storage:contains(number)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function pack_nodes(pos, nvm)
|
|
||||||
local tbl = {}
|
|
||||||
for idx, rpos in ipairs(nvm.lrpos or {}) do
|
|
||||||
local pos2 = vector.add(pos, rpos)
|
|
||||||
local node = minetest.get_node(pos2)
|
|
||||||
print("node", node.name, P2S(pos))
|
|
||||||
local ndef = minetest.registered_nodes[node.name]
|
|
||||||
if ndef and ndef.on_pack then
|
|
||||||
tbl[rpos] = {name = node.name, param2 = node.param2, data = ndef.on_pack(pos2, node)}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return tbl
|
|
||||||
end
|
|
||||||
|
|
||||||
local function unpack_nodes(pos, tbl)
|
|
||||||
for rpos, item in pairs(tbl or {}) do
|
|
||||||
local pos2 = vector.add(pos, rpos)
|
|
||||||
local ndef = minetest.registered_nodes[item.name]
|
|
||||||
if ndef and ndef.on_unpack then
|
|
||||||
ndef.on_unpack(pos2, item.name, item.param2, item.data)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function restore_metadata(itemstack, meta)
|
|
||||||
local imeta = itemstack:get_meta()
|
|
||||||
if imeta then
|
|
||||||
meta:set_string("number", imeta:get_string("number"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function preserve_metadata(pos, oldnode, oldmetadata, drops)
|
|
||||||
local imeta = drops[1]:get_meta()
|
|
||||||
imeta:set_string("description", oldmetadata.infotext)
|
|
||||||
imeta:set_string("number", oldmetadata.number)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function formspec(meta)
|
|
||||||
local status = meta:get_string("status")
|
|
||||||
return "size[8,4]" ..
|
|
||||||
"button[0.7,1.2;3,1;record;" .. S("Record") .. "]" ..
|
|
||||||
"button[4.3,1.2;3,1;ready;" .. S("Done") .. "]" ..
|
|
||||||
"button[0.7,2.2;3,1;pack;" .. S("Pack") .. "]" ..
|
|
||||||
"button[4.3,2.2;3,1;unpack;" .. S("Unpack") .. "]" ..
|
|
||||||
"label[0.5,3.3;" .. status .. "]"
|
|
||||||
end
|
|
||||||
|
|
||||||
local Data = nil
|
|
||||||
|
|
||||||
minetest.register_node("test:container", {
|
|
||||||
description = S("Test Container"),
|
|
||||||
tiles = {
|
|
||||||
"default_chest_top.png",
|
|
||||||
"default_chest_top.png",
|
|
||||||
"default_chest_side.png",
|
|
||||||
"default_chest_side.png",
|
|
||||||
"default_chest_front.png",
|
|
||||||
"default_chest_inside.png"
|
|
||||||
},
|
},
|
||||||
|
},
|
||||||
after_place_node = function(pos, placer, itemstack)
|
tiles = {
|
||||||
local meta = M(pos)
|
-- up, down, right, left, back, front
|
||||||
restore_metadata(itemstack, meta)
|
"signs_bot_sensor2.png^signs_bot_sensor_bot.png",
|
||||||
if not meta:contains("number") then
|
"signs_bot_sensor2.png",
|
||||||
meta:set_string("number", get_number())
|
"signs_bot_sensor2.png",
|
||||||
end
|
"signs_bot_sensor2.png",
|
||||||
meta:set_string("infotext", S("Test Container") .. ": " .. meta:get_string("number"))
|
"signs_bot_sensor2.png",
|
||||||
meta:set_string("formspec", formspec(meta))
|
"signs_bot_sensor2.png",
|
||||||
end,
|
},
|
||||||
|
paramtype = "light",
|
||||||
on_receive_fields = function(pos, formname, fields, player)
|
sunlight_propagates = true,
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
use_texture_alpha = techage.CLIP,
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local meta = M(pos)
|
|
||||||
local nvm = tubelib2.get_mem(pos)
|
|
||||||
local data
|
|
||||||
|
|
||||||
if fields.record then
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
nvm.pos_list = nil
|
|
||||||
nvm.is_on = false
|
|
||||||
meta:set_string("status", S("Recording..."))
|
|
||||||
local name = player:get_player_name()
|
|
||||||
minetest.chat_send_player(name, S("Click on all blocks that shall be moved"))
|
|
||||||
MarkedNodes[name] = {}
|
|
||||||
meta:set_string("formspec", formspec(meta))
|
|
||||||
elseif fields.ready then
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local rpos_list = get_rposlist(pos, name)
|
|
||||||
local text = #rpos_list.." "..S("block positions are stored.")
|
|
||||||
meta:set_string("status", text)
|
|
||||||
nvm.lrpos = rpos_list
|
|
||||||
unmark_all(name)
|
|
||||||
meta:set_string("formspec", formspec(meta))
|
|
||||||
elseif fields.pack and not has_node_data(meta) then
|
|
||||||
data = pack_nodes(pos, nvm)
|
|
||||||
store_node_data(meta, nvm.lrpos, data)
|
|
||||||
meta:set_string("status", S("Packed"))
|
|
||||||
meta:set_string("formspec", formspec(meta))
|
|
||||||
local name = player:get_player_name()
|
|
||||||
MarkedNodes[name] = nil
|
|
||||||
elseif fields.unpack and has_node_data(meta) then
|
|
||||||
nvm.lrpos, data = get_node_data(meta)
|
|
||||||
unpack_nodes(pos, data)
|
|
||||||
meta:set_string("status", S("Unpacked"))
|
|
||||||
meta:set_string("formspec", formspec(meta))
|
|
||||||
local name = player:get_player_name()
|
|
||||||
MarkedNodes[name] = nil
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
|
||||||
end,
|
|
||||||
|
|
||||||
preserve_metadata = preserve_metadata,
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {choppy=2, cracky=2, crumbly=2},
|
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sounds = default.node_sound_wood_defaults(),
|
on_blast = function() end,
|
||||||
|
on_destruct = function () end,
|
||||||
|
can_dig = function() return false end,
|
||||||
|
diggable = false,
|
||||||
|
drop = "",
|
||||||
|
groups = {not_in_creative_inventory = 1},
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
techage.register_node({"techage:ta5_packcontainer_storage"})
|
||||||
if puncher and puncher:is_player() then
|
|
||||||
local name = puncher:get_player_name()
|
|
||||||
|
|
||||||
if not MarkedNodes[name] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
mark_position(name, pointed_thing.under)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
@ -65,8 +65,7 @@ minetest.register_node("techage:ta4_turncontroller", {
|
|||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
|
||||||
if fields.record then
|
if fields.record then
|
||||||
nvm.lpos1 = {}
|
nvm.lpos = {}
|
||||||
nvm.lpos2 = {}
|
|
||||||
meta:set_string("status", S("Recording..."))
|
meta:set_string("status", S("Recording..."))
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
minetest.chat_send_player(name, S("Click on all blocks that shall be turned"))
|
minetest.chat_send_player(name, S("Click on all blocks that shall be turned"))
|
||||||
|
Loading…
Reference in New Issue
Block a user