mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 07:13:48 +01:00
Fix issue #55 (tubelib_addons2:doorblock works incorrectly)
This commit is contained in:
parent
677c1f4148
commit
51fdab3c8a
@ -64,13 +64,16 @@ local Version = minetest.deserialize(storage:get_string("Version")) or 1
|
|||||||
|
|
||||||
local Number2Pos
|
local Number2Pos
|
||||||
local Number2Data
|
local Number2Data
|
||||||
|
local TemporaryRemovedNodes
|
||||||
if Version == 2 then -- legacy data base
|
if Version == 2 then -- legacy data base
|
||||||
Number2Pos = minetest.deserialize(storage:get_string("Number2Pos")) or {}
|
Number2Pos = minetest.deserialize(storage:get_string("Number2Pos")) or {}
|
||||||
Number2Data = extract_data(Number2Pos)
|
Number2Data = extract_data(Number2Pos)
|
||||||
|
TemporaryRemovedNodes = {}
|
||||||
Version = 3
|
Version = 3
|
||||||
else
|
else
|
||||||
Number2Pos = deserialize(storage:get_string("Number2Pos"))
|
Number2Pos = deserialize(storage:get_string("Number2Pos"))
|
||||||
Number2Data = minetest.deserialize(storage:get_string("Number2Data")) or {}
|
Number2Data = minetest.deserialize(storage:get_string("Number2Data")) or {}
|
||||||
|
TemporaryRemovedNodes = minetest.deserialize(storage:get_string("TemporaryRemovedNodes")) or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -82,6 +85,7 @@ local function update_mod_storage()
|
|||||||
storage:set_string("Version", minetest.serialize(Version))
|
storage:set_string("Version", minetest.serialize(Version))
|
||||||
storage:set_string("Number2Pos", serialize(Number2Pos))
|
storage:set_string("Number2Pos", serialize(Number2Pos))
|
||||||
storage:set_string("Number2Data", minetest.serialize(Number2Data))
|
storage:set_string("Number2Data", minetest.serialize(Number2Data))
|
||||||
|
storage:set_string("TemporaryRemovedNodes", minetest.serialize(TemporaryRemovedNodes))
|
||||||
-- store data each hour
|
-- store data each hour
|
||||||
minetest.after(60*59, update_mod_storage)
|
minetest.after(60*59, update_mod_storage)
|
||||||
t = minetest.get_us_time() - t
|
t = minetest.get_us_time() - t
|
||||||
@ -276,7 +280,8 @@ end
|
|||||||
-- param name: name of the data (string)
|
-- param name: name of the data (string)
|
||||||
-- param data: any data (number, string, table)
|
-- param data: any data (number, string, table)
|
||||||
function tubelib.set_data(number, name, data)
|
function tubelib.set_data(number, name, data)
|
||||||
if Number2Data[number] and type(name) == "string" then
|
Number2Data[number] = Number2Data[number] or {}
|
||||||
|
if type(name) == "string" then
|
||||||
Number2Data[number]["u_"..name] = data
|
Number2Data[number]["u_"..name] = data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -591,6 +596,22 @@ function tubelib.get_inv_state(meta, listname)
|
|||||||
return state
|
return state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Mainly used for door/gate nodes
|
||||||
|
-- To delete an entry, provide nil as number. The stored data will be returned.
|
||||||
|
function tubelib.temporary_remove_node(pos, number, name, add_data)
|
||||||
|
local key = get_key_str(pos)
|
||||||
|
if number then
|
||||||
|
add_data = add_data or {}
|
||||||
|
add_data.pos = pos
|
||||||
|
add_data.number = number
|
||||||
|
add_data.name = name
|
||||||
|
TemporaryRemovedNodes[key] = add_data
|
||||||
|
else
|
||||||
|
local data = table.copy(TemporaryRemovedNodes[key])
|
||||||
|
TemporaryRemovedNodes[key] = nil
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Data Maintenance
|
-- Data Maintenance
|
||||||
@ -622,41 +643,6 @@ local function get_node_number(pos)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local NodesWithoutNumber = {
|
|
||||||
["tubelib_addons2:doorblock1"] = true,
|
|
||||||
["tubelib_addons2:doorblock2"] = true,
|
|
||||||
["tubelib_addons2:doorblock3"] = true,
|
|
||||||
["tubelib_addons2:doorblock4"] = true,
|
|
||||||
["tubelib_addons2:doorblock5"] = true,
|
|
||||||
["tubelib_addons2:doorblock6"] = true,
|
|
||||||
["tubelib_addons2:doorblock7"] = true,
|
|
||||||
["tubelib_addons2:doorblock8"] = true,
|
|
||||||
["tubelib_addons2:doorblock9"] = true,
|
|
||||||
["tubelib_addons2:doorblock10"] = true,
|
|
||||||
["tubelib_addons2:doorblock11"] = true,
|
|
||||||
["tubelib_addons2:doorblock12"] = true,
|
|
||||||
["tubelib_addons2:doorblock13"] = true,
|
|
||||||
["tubelib_addons2:doorblock14"] = true,
|
|
||||||
["tubelib_addons2:gateblock1"] = true,
|
|
||||||
["tubelib_addons2:gateblock2"] = true,
|
|
||||||
["tubelib_addons2:gateblock3"] = true,
|
|
||||||
["tubelib_addons2:gateblock4"] = true,
|
|
||||||
["tubelib_addons2:gateblock5"] = true,
|
|
||||||
["tubelib_addons2:gateblock6"] = true,
|
|
||||||
["tubelib_addons2:gateblock7"] = true,
|
|
||||||
["tubelib_addons2:gateblock8"] = true,
|
|
||||||
["tubelib_addons2:gateblock9"] = true,
|
|
||||||
["tubelib_addons2:gateblock10"] = true,
|
|
||||||
["tubelib_addons2:gateblock11"] = true,
|
|
||||||
["tubelib_addons2:gateblock12"] = true,
|
|
||||||
["tubelib_addons2:gateblock13"] = true,
|
|
||||||
["tubelib_addons2:gateblock14"] = true,
|
|
||||||
["tubelib_addons2:gateblock15"] = true,
|
|
||||||
["tubelib_addons2:gateblock16"] = true,
|
|
||||||
["tubelib_addons2:gateblock17"] = true,
|
|
||||||
["tubelib_addons2:gateblock18"] = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
local function data_maintenance()
|
local function data_maintenance()
|
||||||
minetest.log("info", "[Tubelib] Data maintenance started")
|
minetest.log("info", "[Tubelib] Data maintenance started")
|
||||||
|
|
||||||
@ -670,14 +656,28 @@ local function data_maintenance()
|
|||||||
cnt1 = cnt1 + 1
|
cnt1 = cnt1 + 1
|
||||||
-- Is there a tubelib node?
|
-- Is there a tubelib node?
|
||||||
if tubelib_NodeDef[name] then
|
if tubelib_NodeDef[name] then
|
||||||
local nnum = get_node_number(item.pos)
|
|
||||||
-- Does the number match?
|
-- Does the number match?
|
||||||
if nnum == num or NodesWithoutNumber[name] then
|
local nnum = get_node_number(item.pos)
|
||||||
|
if nnum == num then
|
||||||
cnt2 = cnt2 + 1
|
cnt2 = cnt2 + 1
|
||||||
-- Store again
|
-- Store again
|
||||||
Number2Pos[num] = item
|
Number2Pos[num] = item
|
||||||
-- Add node names which are not stored as file
|
-- Add node names which are not stored as file
|
||||||
Number2Pos[num].name = name
|
Number2Pos[num].name = name
|
||||||
|
--print("added", num, name)
|
||||||
|
else
|
||||||
|
--print("wrong number", num, name)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local key = get_key_str(item.pos)
|
||||||
|
local data = TemporaryRemovedNodes[key]
|
||||||
|
if data then
|
||||||
|
cnt2 = cnt2 + 1
|
||||||
|
-- Store again
|
||||||
|
Number2Pos[data.number] = data
|
||||||
|
--print("restored", data.number, data.name)
|
||||||
|
else
|
||||||
|
--print("no data", num)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -52,8 +52,7 @@ for idx,pgn in ipairs(tPgns) do
|
|||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local number = tubelib.add_node(pos, "tubelib_addons2:doorblock"..idx)
|
local number = tubelib.add_node(pos, node.name)
|
||||||
tubelib.set_data(number, "facedir", node.param2)
|
|
||||||
meta:set_string("number", number)
|
meta:set_string("number", number)
|
||||||
meta:set_string("infotext", "Tubelib Door Block "..number)
|
meta:set_string("infotext", "Tubelib Door Block "..number)
|
||||||
meta:set_string("formspec", "size[3,2]"..
|
meta:set_string("formspec", "size[3,2]"..
|
||||||
@ -65,11 +64,10 @@ for idx,pgn in ipairs(tPgns) do
|
|||||||
on_receive_fields = function(pos, formname, fields, player)
|
on_receive_fields = function(pos, formname, fields, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local number = meta:get_string("number")
|
|
||||||
if fields.type then
|
if fields.type then
|
||||||
node.name = "tubelib_addons2:doorblock"..tTextures[fields.type]
|
node.name = "tubelib_addons2:doorblock"..tTextures[fields.type]
|
||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
tubelib.set_data(number, "texture", node.name)
|
tubelib.add_node(pos, node.name)
|
||||||
end
|
end
|
||||||
if fields.exit then
|
if fields.exit then
|
||||||
meta:set_string("formspec", nil)
|
meta:set_string("formspec", nil)
|
||||||
@ -96,14 +94,16 @@ for idx,pgn in ipairs(tPgns) do
|
|||||||
on_recv_message = function(pos, topic, payload)
|
on_recv_message = function(pos, topic, payload)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if topic == "on" then
|
if topic == "on" then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local number = meta:get_string("number")
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
|
tubelib.temporary_remove_node(pos, number, node.name, {param2 = node.param2})
|
||||||
elseif topic == "off" then
|
elseif topic == "off" then
|
||||||
local num = tubelib.get_node_number(pos)
|
local data = tubelib.temporary_remove_node(pos)
|
||||||
local name = tubelib.get_data(num, "texture") or "tubelib_addons2:doorblock1"
|
if data then
|
||||||
if name then
|
minetest.add_node(pos, {name = data.name, param2 = data.param2})
|
||||||
minetest.add_node(pos, {name=name,
|
local meta = minetest.get_meta(pos)
|
||||||
paramtype2="facedir",
|
meta:set_string("number", data.number)
|
||||||
param2=tubelib.get_data(num, "facedir")})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -34,6 +34,7 @@ local tPgns = {"default_wood.png", "default_aspen_wood.png", "default_junglewood
|
|||||||
"default_copper_block.png", "default_steel_block.png", "default_tin_block.png", "default_coral_skeleton.png",
|
"default_copper_block.png", "default_steel_block.png", "default_tin_block.png", "default_coral_skeleton.png",
|
||||||
"default_glass.png", "default_obsidian_glass.png", "default_ice.png", "tubelib_addon2_gate.png"}
|
"default_glass.png", "default_obsidian_glass.png", "default_ice.png", "tubelib_addon2_gate.png"}
|
||||||
|
|
||||||
|
local not_in_inventory=nil
|
||||||
for idx,pgn in ipairs(tPgns) do
|
for idx,pgn in ipairs(tPgns) do
|
||||||
minetest.register_node("tubelib_addons2:gateblock"..idx, {
|
minetest.register_node("tubelib_addons2:gateblock"..idx, {
|
||||||
description = "Tubelib Gate Block",
|
description = "Tubelib Gate Block",
|
||||||
@ -41,7 +42,8 @@ for idx,pgn in ipairs(tPgns) do
|
|||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local number = tubelib.add_node(pos, "tubelib_addons2:gateblock"..idx)
|
local number = tubelib.add_node(pos, node.name)
|
||||||
|
meta:set_string("number", number)
|
||||||
meta:set_string("infotext", "Tubelib Gate Block "..number)
|
meta:set_string("infotext", "Tubelib Gate Block "..number)
|
||||||
meta:set_string("formspec", "size[3,2]"..
|
meta:set_string("formspec", "size[3,2]"..
|
||||||
"label[0,0;Select texture]"..
|
"label[0,0;Select texture]"..
|
||||||
@ -62,7 +64,7 @@ for idx,pgn in ipairs(tPgns) do
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
after_dig_node = function(pos)
|
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||||
tubelib.remove_node(pos)
|
tubelib.remove_node(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -71,7 +73,7 @@ for idx,pgn in ipairs(tPgns) do
|
|||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
groups = {cracky=2, choppy=2, crumbly=2, not_in_creative_inventory = idx==NUM_TEXTURES and 0 or 1},
|
groups = {cracky=2, choppy=2, crumbly=2, not_in_creative_inventory=not_in_inventory},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
drop = "tubelib_addons2:gateblock1",
|
drop = "tubelib_addons2:gateblock1",
|
||||||
})
|
})
|
||||||
@ -82,12 +84,16 @@ for idx,pgn in ipairs(tPgns) do
|
|||||||
on_recv_message = function(pos, topic, payload)
|
on_recv_message = function(pos, topic, payload)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if topic == "on" then
|
if topic == "on" then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local number = meta:get_string("number")
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
|
tubelib.temporary_remove_node(pos, number, node.name, {param2 = node.param2})
|
||||||
elseif topic == "off" then
|
elseif topic == "off" then
|
||||||
local num = tubelib.get_node_number(pos)
|
local data = tubelib.temporary_remove_node(pos)
|
||||||
local info = tubelib.get_node_info(num)
|
if data then
|
||||||
if info then
|
minetest.add_node(pos, {name = data.name, param2 = data.param2})
|
||||||
minetest.add_node(pos, {name=info.name})
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("number", data.number)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
Loading…
Reference in New Issue
Block a user