Compare commits

...

7 Commits

Author SHA1 Message Date
Joachim Stolberg
8e2b7bbd07 Add pack controller 2022-02-08 21:18:41 +01:00
Joachim Stolberg
b917f63dc0 Add pack controller 2022-02-06 21:49:05 +01:00
Joachim Stolberg
bec48ca37f Add pack controller 2022-02-06 15:44:38 +01:00
Joachim Stolberg
93ce219eec Add pack lib 2022-01-31 18:59:17 +01:00
Joachim Stolberg
68deb3723a Add pack controller 2022-01-30 11:25:49 +01:00
Joachim Stolberg
62b06791f9 Fix marshal issues 2022-01-30 11:25:09 +01:00
Joachim Stolberg
3cb7b4f53e Fix marshal issues 2022-01-30 11:24:48 +01:00
17 changed files with 605 additions and 81 deletions

View File

@ -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

View File

@ -692,13 +692,7 @@ function flylib.rotate_nodes(pos, posses1, rot)
for i, pos1 in ipairs(posses1) do for i, pos1 in ipairs(posses1) do
local node = techage.get_node_lvm(pos1) local node = techage.get_node_lvm(pos1)
if rot == "l" then param2 = techage.rotate_param2(node, rot)
param2 = techage.param2_turn_right(node.param2)
elseif rot == "r" then
param2 = techage.param2_turn_left(node.param2)
else
param2 = techage.param2_turn_right(techage.param2_turn_right(node.param2))
end
if not minetest.is_protected(pos1, owner) and is_simple_node(pos1) then if not minetest.is_protected(pos1, owner) and is_simple_node(pos1) then
minetest.remove_node(pos1) minetest.remove_node(pos1)
nodes2[#nodes2 + 1] = {pos = posses2[i], name = node.name, param2 = param2} nodes2[#nodes2 + 1] = {pos = posses2[i], name = node.name, param2 = param2}

View File

@ -64,6 +64,10 @@ local FACEDIR_TO_ROT = {[0] =
{x=0.000000, y=4.712389, z=3.141593}, {x=0.000000, y=4.712389, z=3.141593},
} }
-- 0 1 2 3 4 5
local WALLMOUNTED_TO_RIGHT = {[0]=0, 1, 5, 4, 2, 3}
local WALLMOUNTED_TO_LEFT = {[0]=0, 1, 4, 5, 3, 2}
local RotationViaYAxis = {} local RotationViaYAxis = {}
for _,row in ipairs(ROTATION) do for _,row in ipairs(ROTATION) do
@ -80,11 +84,11 @@ function techage.facedir_to_rotation(facedir)
end end
function techage.param2_turn_left(param2) function techage.param2_turn_left(param2)
return (RotationViaYAxis[param2] or RotationViaYAxis[0])[2] return (RotationViaYAxis[param2] or RotationViaYAxis[0])[1]
end end
function techage.param2_turn_right(param2) function techage.param2_turn_right(param2)
return (RotationViaYAxis[param2] or RotationViaYAxis[0])[1] return (RotationViaYAxis[param2] or RotationViaYAxis[0])[2]
end end
-- Roll a block in north direction (south is vice versa) -- Roll a block in north direction (south is vice versa)
@ -133,6 +137,91 @@ end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Rotate nodes around the center -- Rotate nodes around the center
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- turn is one of "l", "r", "2l", "2r", or ""
function techage.rotate_param2(node, turn)
print("calc_node_param2", turn)
local ndef = minetest.registered_nodes[node.name]
if ndef then
print("calc_node_param2", ndef.paramtype2)
if ndef.paramtype2 == "facedir" then
if turn == "l" then
return techage.param2_turn_left(node.param2)
elseif turn == "r" then
return techage.param2_turn_right(node.param2)
elseif turn == "" then
return node.param2
else
return techage.param2_turn_right(techage.param2_turn_right(node.param2))
end
elseif ndef.paramtype2 == "colorfacedir" then
local param2 = math.floor(node.param2 % 32)
if turn == "l" then
param2 = techage.param2_turn_left(param2)
elseif turn == "r" then
param2 = techage.param2_turn_right(param2)
elseif turn == "" then
param2 = param2
else
param2 = techage.param2_turn_right(param2)
param2 = techage.param2_turn_right(param2)
end
-- Add color again
return math.floor(node.param2 / 32) * 32 + param2
elseif ndef.paramtype2 == "wallmounted" then
if turn == "l" then
return WALLMOUNTED_TO_LEFT[node.param2]
elseif turn == "r" then
return WALLMOUNTED_TO_RIGHT[node.param2]
elseif turn == "" then
return node.param2
else
return WALLMOUNTED_TO_RIGHT[WALLMOUNTED_TO_RIGHT[node.param2]]
end
elseif ndef.paramtype2 == "colorwallmounted" then
local param2 = math.floor(node.param2 % 8)
if turn == "l" then
param2 = WALLMOUNTED_TO_LEFT[param2]
elseif turn == "r" then
param2 = WALLMOUNTED_TO_RIGHT[param2]
elseif turn == "" then
param2 = param2
else
param2 = WALLMOUNTED_TO_RIGHT[param2]
param2 = WALLMOUNTED_TO_RIGHT[param2]
end
-- Add color again
return math.floor(node.param2 / 8) * 8 + param2
elseif ndef.paramtype2 == "degrotate" then
local rot = (node.param2 * 1.5) + 360
if turn == "l" then
rot = rot + 90
elseif turn == "r" then
rot = rot - 90
elseif turn == "" then
rot = rot + 0
else
rot = rot + 180
end
return math.floor((rot % 360) / 1.5)
elseif ndef.paramtype2 == "colordegrotate" then
local param2 = node.param2 % 32
local rot = (param2 * 15) + 360
if turn == "l" then
rot = rot + 90
elseif turn == "r" then
rot = rot - 90
elseif turn == "" then
rot = rot + 0
else
rot = rot + 180
end
-- Add color again
return math.floor(node.param2 / 32) * 32 + math.floor((rot % 360) / 15)
end
end
return node.param2
end
function techage.positions_center(lpos) function techage.positions_center(lpos)
local c = {x=0, y=0, z=0} local c = {x=0, y=0, z=0}
for _,v in ipairs(lpos) do for _,v in ipairs(lpos) do
@ -244,6 +333,17 @@ function techage.add_to_set(set, x)
end end
end end
-- techage.tbl_filter({"a", "b", "c", "d"}, function(v, k, t) return v >= "c" end) --> {"c","d"}
techage.tbl_filter = function(t, filterIter)
local out = {}
for k, v in pairs(t) do
if filterIter(v, k, t) then out[k] = v end
end
return out
end
function techage.get_node_lvm(pos) function techage.get_node_lvm(pos)
local node = minetest.get_node_or_nil(pos) local node = minetest.get_node_or_nil(pos)
if node then if node then

54
basis/marshal.lua Normal file
View File

@ -0,0 +1,54 @@
--[[
TechAge
=======
Copyright (C) 2019-2022 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
]]--
-------------------------------------------------------------------
-- Marshaling: Returns serialize, deserialize functions
-------------------------------------------------------------------
local use_marshal = minetest.settings:get_bool('techage_use_marshal', false)
local MAR_MAGIC = 0x8e
local marshal = techage.IE.require("marshal")
if use_marshal then
if not techage.IE then
error("Please add 'secure.trusted_mods = techage' to minetest.conf!")
end
marshal = techage.IE.require("marshal")
if not marshal then
error("Please install marshal via 'luarocks install lua-marshal'")
end
elseif techage.IE then
marshal = techage.IE.require("marshal")
end
if marshal then
return marshal.encode,
function(s)
if s ~= "" then
if s:byte(1) == MAR_MAGIC then
return marshal.decode(s)
else
return minetest.deserialize(s)
end
end
end
else
return minetest.serialize,
function(s)
if s ~= "" then
if s:byte(1) == MAR_MAGIC then
error("'lua-marshal' is required to deserialize this string")
else
return minetest.deserialize(s)
end
end
end
end

View File

@ -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 {}

View File

@ -17,37 +17,8 @@ local M = minetest.get_meta
local storage = techage.storage local storage = techage.storage
------------------------------------------------------------------- local MP = minetest.get_modpath("techage")
-- Marshaling local serialize, deserialize = dofile(MP .. "/basis/marshal.lua")
-------------------------------------------------------------------
local use_marshal = minetest.settings:get_bool('techage_use_marshal', false)
local MAR_MAGIC = 0x8e
-- default functions
local serialize = minetest.serialize
local deserialize = minetest.deserialize
if use_marshal then
if not techage.IE then
error("Please add 'secure.trusted_mods = techage' to minetest.conf!")
end
local marshal = techage.IE.require("marshal")
if not marshal then
error("Please install marshal via 'luarocks install lua-marshal'")
end
serialize = marshal.encode
deserialize = function(s)
if s ~= "" then
if s:byte(1) == MAR_MAGIC then
return marshal.decode(s)
else
return minetest.deserialize(s)
end
end
end
end
------------------------------------------------------------------- -------------------------------------------------------------------
-- API functions -- API functions
@ -86,15 +57,17 @@ function api.get_node_data(pos)
end end
-- Meta data can't be written reliable at shutdown, -- Meta data can't be written reliable at shutdown,
-- so we have to store/restore the data differently -- so we have to store/restore the data differently.
function api.freeze_at_shutdown(data) function api.freeze_at_shutdown(data)
storage:set_string("shutdown_nodedata", serialize(data)) -- We use the minetest serialize function, because marshal.encode
-- generates a binary string, which can't be stored in storage.
storage:set_string("shutdown_nodedata", minetest.serialize(data))
end end
function api.restore_at_startup() function api.restore_at_startup()
local s = storage:get_string("shutdown_nodedata") local s = storage:get_string("shutdown_nodedata")
if s ~= "" then if s ~= "" then
return deserialize(s) or {} return minetest.deserialize(s) or {}
end end
return {} return {}
end end

View File

@ -18,23 +18,17 @@ local M = minetest.get_meta
------------------------------------------------------------------- -------------------------------------------------------------------
-- Database -- Database
------------------------------------------------------------------- -------------------------------------------------------------------
local MN = minetest.get_current_modname()
local WP = minetest.get_worldpath() local WP = minetest.get_worldpath()
local MAR_MAGIC = 0x8e
if not techage.IE then if not techage.IE then
error("Please add 'secure.trusted_mods = techage' to minetest.conf!") error("Please add 'secure.trusted_mods = techage' to minetest.conf!")
end end
local sqlite3 = techage.IE.require("lsqlite3") local sqlite3 = techage.IE.require("lsqlite3")
local marshal = techage.IE.require("marshal")
if not sqlite3 then if not sqlite3 then
error("Please install sqlite3 via 'luarocks install lsqlite3'") error("Please install sqlite3 via 'luarocks install lsqlite3'")
end end
if not marshal then
error("Please install marshal via 'luarocks install lua-marshal'")
end
local db = sqlite3.open(WP.."/techage_nodedata.sqlite") local db = sqlite3.open(WP.."/techage_nodedata.sqlite")
local ROW = sqlite3.ROW local ROW = sqlite3.ROW
@ -71,21 +65,18 @@ end
------------------------------------------------------------------- -------------------------------------------------------------------
local api = {} local api = {}
local MP = minetest.get_modpath("techage")
local serialize, deserialize = dofile(MP .. "/basis/marshal.lua")
function api.store_mapblock_data(key, mapblock_data) function api.store_mapblock_data(key, mapblock_data)
-- deactivated due to weird server crashes without error logs local s = serialize(mapblock_data)
--local s = marshal.encode(mapblock_data)
local s = minetest.serialize(mapblock_data)
return set_block(key, s) return set_block(key, s)
end end
function api.get_mapblock_data(key) function api.get_mapblock_data(key)
local s = get_block(key) local s = get_block(key)
if s then if s then
if s:byte(1) == MAR_MAGIC then return deserialize(s)
return marshal.decode(s)
else
return minetest.deserialize(s)
end
end end
api.store_mapblock_data(key, {}) api.store_mapblock_data(key, {})
return {} return {}
@ -96,11 +87,7 @@ function api.get_node_data(pos)
local s = M(pos):get_string("ta_data") local s = M(pos):get_string("ta_data")
if s ~= "" then if s ~= "" then
M(pos):set_string("ta_data", "") M(pos):set_string("ta_data", "")
if s:byte(1) == MAR_MAGIC then return deserialize(s)
return marshal.decode(s)
else
return minetest.deserialize(s)
end
end end
return {} return {}
end end

View File

@ -12,31 +12,22 @@
]]-- ]]--
-- for lazy programmers
local M = minetest.get_meta
local storage = techage.storage local storage = techage.storage
------------------------------------------------------------------- -------------------------------------------------------------------
-- Database -- Database
------------------------------------------------------------------- -------------------------------------------------------------------
local MN = minetest.get_current_modname()
local WP = minetest.get_worldpath() local WP = minetest.get_worldpath()
local MAR_MAGIC = 0x8e
if not techage.IE then if not techage.IE then
error("Please add 'secure.trusted_mods = techage' to minetest.conf!") error("Please add 'secure.trusted_mods = techage' to minetest.conf!")
end end
local sqlite3 = techage.IE.require("lsqlite3") local sqlite3 = techage.IE.require("lsqlite3")
local marshal = techage.IE.require("marshal")
if not sqlite3 then if not sqlite3 then
error("Please install sqlite3 via 'luarocks install lsqlite3'") error("Please install sqlite3 via 'luarocks install lsqlite3'")
end end
if not marshal then
error("Please install marshal via 'luarocks install lua-marshal'")
end
local db = sqlite3.open(WP.."/techage_numbers.sqlite") local db = sqlite3.open(WP.."/techage_numbers.sqlite")
local ROW = sqlite3.ROW local ROW = sqlite3.ROW
@ -129,7 +120,7 @@ end
-- delete invalid entries -- delete invalid entries
function api.delete_invalid_entries(node_def) function api.delete_invalid_entries(node_def)
minetest.log("info", "[TechAge] Data maintenance started") minetest.log("info", "[TechAge] Data maintenance started")
for id, num, x, y, z in db:urows('SELECT * FROM numbers') do for _, num, x, y, z in db:urows('SELECT * FROM numbers') do
local pos = {x = x, y = y, z = z} local pos = {x = x, y = y, z = z}
local name = techage.get_node_lvm(pos).name local name = techage.get_node_lvm(pos).name
if not node_def[name] then if not node_def[name] then

179
basis/pack_lib.lua Normal file
View File

@ -0,0 +1,179 @@
--[[
TechAge
=======
Copyright (C) 2019-2022 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
Packing functions
]]--
-- for lazy programmers
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local M = minetest.get_meta
-- string/usercode conversion
local function usercode_to_string(tbl)
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
local function string_to_usercode(tbl)
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
-- pack/unpack node nvm data
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
nvm.k = v
end
end
-- pack/unpack node metedata
function techage.pack_meta(pos)
local tbl = M(pos):to_table() or {}
usercode_to_string(tbl)
return minetest.serialize(tbl)
end
function techage.unpack_meta(pos, s)
local tbl = minetest.deserialize(s) or {}
string_to_usercode(tbl)
M(pos):from_table(tbl)
end
-- on_pack/on_unpack fallback functions
local function on_pack_fallback_(pos, node)
--print("on_pack_fallback_",P2S(pos), node.name)
local smeta = techage.pack_meta(pos)
local snvm = techage.pack_nvm(pos)
minetest.remove_node(pos)
return {smeta = smeta, snvm = snvm}
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
-------------------------------------------------------------------------------
-- pos_list is a list of node positions
function techage.pack_nodes(pos_list)
local pack_tbl = {}
for _, pos2 in ipairs(pos_list or {}) do
local node = minetest.get_node(pos2)
local ndef = minetest.registered_nodes[node.name]
if ndef and ndef.on_pack then
pack_tbl[pos2] = {name = node.name, param2 = node.param2, data = ndef.on_pack(pos2, node)}
else
pack_tbl[pos2] = {name = node.name, param2 = node.param2, data = on_pack_fallback_(pos2, node)}
end
end
return pack_tbl
end
function techage.unpack_nodes(pack_tbl)
-- Check positions
for pos2, _ in pairs(pack_tbl or {}) do
local node = minetest.get_node(pos2)
if not techage.is_air_like(node.name) then
return false
end
end
-- Place nodes
for pos2, item in pairs(pack_tbl or {}) do
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
return true
end
-------------------------------------------------------------------------------
-- move/turn API functions
-------------------------------------------------------------------------------
function techage.determine_turn_rotation(old_param2, new_param2)
local offs = new_param2 - old_param2
if offs == -1 or offs == 3 then return "l"
elseif offs == 1 or offs == -3 then return "r"
elseif offs == 2 or offs == -2 then return "2r"
else return "" end
end
-- move is the distance between old and new pos as vector
function techage.adjust_pos_list_move(pos_list, move)
local out = {}
for idx, pos in ipairs(pos_list or {}) do
local pos2 = vector.add(pos, move)
out[idx] = pos2
end
return out
end
-- Adjust the data for a turn of all nodes around cpos
-- turn is one of "l", "r", "2l", "2r"
function techage.adjust_pos_list_turn(cpos, pos_list, turn)
local out = {}
for idx, npos in ipairs(pos_list or {}) do
local pos2 = techage.rotate_around_axis(npos, cpos, turn)
out[idx] = pos2
end
return out
end
-- move is the distance between old and new pos as vector
function techage.adjust_pack_tbl_move(pack_tbl, move)
local out = {}
for pos, item in pairs(pack_tbl or {}) do
local pos2 = vector.add(pos, move)
out[pos2] = item
end
return out
end
-- Adjust the data for a turn of all nodes around cpos
-- turn is one of "l", "r", "2l", "2r"
function techage.adjust_pack_tbl_turn(cpos, pack_tbl, turn)
local out = {}
for npos, item in pairs(pack_tbl or {}) do
item.param2 = techage.rotate_param2(item, turn)
local pos2 = techage.rotate_around_axis(npos, cpos, turn)
out[pos2] = item
end
return out
end

View File

@ -46,6 +46,7 @@ local function count_trues(t)
end end
local function nucleus(t) local function nucleus(t)
t = techage.tbl_filter(t, function(v, k, t) return type(v) == "table" end)
if #t == 4 then if #t == 4 then
if vector.equals(t[1], t[2]) and vector.equals(t[3], t[4]) then if vector.equals(t[1], t[2]) and vector.equals(t[3], t[4]) then
return true return true

View File

@ -104,6 +104,7 @@ dofile(MP.."/basis/submenu.lua")
dofile(MP.."/basis/shared_inv.lua") dofile(MP.."/basis/shared_inv.lua")
dofile(MP.."/basis/shared_tank.lua") dofile(MP.."/basis/shared_tank.lua")
dofile(MP.."/basis/teleport.lua") dofile(MP.."/basis/teleport.lua")
dofile(MP.."/basis/pack_lib.lua")
-- Main doc -- Main doc
dofile(MP.."/doc/manual_DE.lua") dofile(MP.."/doc/manual_DE.lua")
@ -306,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")
@ -414,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

View File

@ -1403,7 +1403,7 @@ TA5 Turbine=TA5 Turbine
### turncontroller.lua ### ### turncontroller.lua ###
Click on all blocks that shall be turned=Klicke auf all Blöcke, die gedreht werden sollen Click on all blocks that shall be turned=Klicke auf alle Blöcke, die gedreht werden sollen
TA4 Turn Controller=TA4 Dreh Controller TA4 Turn Controller=TA4 Dreh Controller
Turn left=Drehe links Turn left=Drehe links
Turn right=Drehe rechts Turn right=Drehe rechts

View File

@ -0,0 +1,234 @@
--[[
TechAge
=======
Copyright (C) 2020-2022 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
TA5 Pack Container
]]--
-- for lazy programmers
local M = minetest.get_meta
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local S2P = minetest.string_to_pos
local S = techage.S
local MP = minetest.get_modpath("techage")
local fly = dofile(MP .. "/basis/fly_lib.lua")
local mark = dofile(MP .. "/basis/mark_lib.lua")
local MAX_BLOCKS = 16
local DESCRIPTION = S("TA5 Pack Container")
local function formspec(nvm, meta)
local status = meta:get_string("status")
local path = meta:contains("path") and meta:get_string("path") or "0,3,0"
local node_name = meta:get_string("node_name")
return "size[8,4.3]" ..
"box[0,-0.1;7.8,0.5;#c6e8ff]" ..
"label[0.2,-0.1;" .. minetest.colorize( "#000000", DESCRIPTION) .. "]" ..
--techage.wrench_image(7.4, -0.05) ..
"field[0.4,1.2;3.8,1;node_name;" .. S("Node name") .. ";" .. node_name .. "]" ..
"button[4.1,0.9;3.8,1;store;" .. S("Store") .. "]" ..
"button[0.1,2.1;3.8,1;record;" .. S("Record") .. "]" ..
"box[0,1.9;7.8,0.02;#ffffff]" ..
"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,3.9;" .. status .. "]"
end
local function set_storage_pos(pos, oldnode, oldmetadata, drops)
if oldmetadata.data_stored == "1" then
local meta = drops[1]:get_meta()
meta:set_string("storage_pos", P2S(pos))
meta:set_string("node_name", oldmetadata.node_name or "")
meta:set_string("status", oldmetadata.status or "")
meta:set_int("data_stored", 1)
meta:set_string("description", DESCRIPTION .. ' "' .. (oldmetadata.node_name or "") .. '"')
end
end
local function get_storage_pos(pos, itemstack)
local imeta = itemstack:get_meta()
if imeta then
local meta = M(pos)
meta:set_string("node_name", imeta:get_string("node_name"))
meta:set_string("status", imeta:get_string("status"))
meta:set_int("data_stored", imeta:get_int("data_stored"))
local pos2 = S2P(imeta:get_string("storage_pos"))
if pos2 then
local node = techage.get_node_lvm(pos2)
if node.name == "techage:ta5_packcontainer_storage" then
return pos2, node.param2
end
end
end
end
local function takeover_data(old_pos, new_pos)
local nvm1 = techage.get_nvm(old_pos)
local nvm2 = techage.get_nvm(new_pos)
nvm2.pos_list = nvm1.pos_list
nvm2.pack_tbl = nvm1.pack_tbl
end
local function remove_storage_node(old_pos)
minetest.remove_node(old_pos)
techage.del_mem(old_pos)
end
local function adjust_database(pos, nvm, move, turn)
nvm.pos_list = techage.adjust_pos_list_move(nvm.pos_list, move)
nvm.pos_list = techage.adjust_pos_list_turn(pos, nvm.pos_list, turn)
nvm.pack_tbl = techage.adjust_pack_tbl_move(nvm.pack_tbl, move)
nvm.pack_tbl = techage.adjust_pack_tbl_turn(pos, nvm.pack_tbl, turn)
end
local function after_place_node(pos, placer, itemstack)
local nvm = techage.get_nvm(pos)
local meta = M(pos)
meta:set_string("infotext", DESCRIPTION)
meta:set_string("owner", placer:get_player_name())
local old_pos, old_param2 = get_storage_pos(pos, itemstack)
if old_pos then
local new_param2 = minetest.get_node(pos).param2
local turn = techage.determine_turn_rotation(old_param2, new_param2)
local move = vector.subtract(pos, old_pos)
takeover_data(old_pos, pos)
adjust_database(pos, nvm, move, turn)
remove_storage_node(old_pos)
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
return
end
local meta = M(pos)
local nvm = techage.get_nvm(pos)
local data_stored = meta:get_int("data_stored") == 1
if fields.record and not data_stored then
nvm.pos_list = nil
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 turned"))
mark.start(name, MAX_BLOCKS)
meta:set_string("formspec", formspec(nvm, meta))
elseif fields.store and not data_stored then
meta:set_string("node_name", fields.node_name)
meta:set_string("formspec", formspec(nvm, meta))
elseif fields.done and not data_stored then
local name = player:get_player_name()
nvm.pos_list = mark.get_poslist(name) or {}
local text = #(nvm.pos_list).." "..S("block positions are stored.")
meta:set_string("status", text)
meta:set_string("node_name", fields.node_name)
mark.unmark_all(name)
mark.stop(name)
meta:set_string("formspec", formspec(nvm, meta))
elseif fields.pack and nvm.pos_list and #nvm.pos_list > 0 and not data_stored then
nvm.pack_tbl = techage.pack_nodes(nvm.pos_list)
meta:set_string("status", S("Blocks stored"))
meta:set_string("formspec", formspec(nvm, meta))
meta:set_int("data_stored", 1)
elseif fields.unpack and data_stored and nvm.pack_tbl then
if techage.unpack_nodes(nvm.pack_tbl) then
meta:set_string("status", S("Blocks placed"))
meta:set_int("data_stored", 0)
else
meta:set_string("status", S("Position(s) occupied"))
end
meta:set_string("formspec", formspec(nvm, meta))
end
end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
local name = digger:get_player_name()
mark.unmark_all(name)
mark.stop(name)
if oldmetadata.fields.data_stored == "1" then
minetest.set_node(pos, {name = "techage:ta5_packcontainer_storage", param2 = oldnode.param2})
local owner = oldmetadata.fields.owner or ""
M(pos):set_string("infotext", S("@1's @2 storage", owner, DESCRIPTION))
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_appl_arrow.png",
"techage_filling_ta4.png^techage_frame_ta5_top.png",
"techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_pack.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",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
local INFO = [[Commands: 'left', 'right', 'uturn']]
techage.register_node({"techage:ta5_packcontainer"}, {
on_recv_message = function(pos, src, topic, payload)
if topic == "info" then
return INFO
end
return false
end,
})
minetest.register_craft({
output = "techage:ta4_turncontroller",
recipe = {
{"default:steel_ingot", "dye:blue", "default:steel_ingot"},
{"techage:aluminum", "techage:baborium_ingot", "techage:aluminum"},
{"group:wood", "basic_materials:gear_steel", "group:wood"},
},
})
minetest.register_node("techage:ta5_packcontainer_storage", {
description = DESCRIPTION,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -5/16, -8/16, -5/16, 5/16, -5/16, 5/16},
},
},
tiles = {
-- up, down, right, left, back, front
"techage_pack_storage.png",
},
paramtype2 = "facedir",
paramtype = "light",
sunlight_propagates = true,
light_source = 5,
glow = 12,
use_texture_alpha = techage.CLIP,
is_ground_content = false,
on_blast = function() end,
on_destruct = function () end,
can_dig = function() return false end,
diggable = false,
drop = "",
groups = {not_in_creative_inventory = 1},
})
techage.register_node({"techage:ta5_packcontainer_storage"})

View File

@ -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"))

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

View File

@ -69,7 +69,8 @@ local function turn_node_param2(pos, node, ndef, user)
end end
local function turn_left(pos, node, ndef) local function turn_left(pos, node, ndef)
local param2 = techage.param2_turn_left(node.param2) -- Turn face left means turn block right
local param2 = techage.param2_turn_right(node.param2)
if ndef.ta_rotate_node then if ndef.ta_rotate_node then
ndef.ta_rotate_node(pos, node, param2) ndef.ta_rotate_node(pos, node, param2)
else else