mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-25 16:43:50 +01:00
fix crash when tube too long (and spurious whitespace changes)
This commit is contained in:
parent
d6b0696746
commit
342083bf03
@ -32,7 +32,7 @@ local function update_mod_storage()
|
|||||||
storage:set_string("NextNumber", minetest.serialize(NextNumber))
|
storage:set_string("NextNumber", minetest.serialize(NextNumber))
|
||||||
storage:set_string("Version", minetest.serialize(Version))
|
storage:set_string("Version", minetest.serialize(Version))
|
||||||
storage:set_string("Number2Pos", minetest.serialize(Number2Pos))
|
storage:set_string("Number2Pos", minetest.serialize(Number2Pos))
|
||||||
storage:set_string("Key2Number", nil) -- not used any more
|
storage:set_string("Key2Number", nil) -- not used any more
|
||||||
-- store data each hour
|
-- store data each hour
|
||||||
minetest.after(60*59, update_mod_storage)
|
minetest.after(60*59, update_mod_storage)
|
||||||
minetest.log("action", "[Tubelib] Data stored")
|
minetest.log("action", "[Tubelib] Data stored")
|
||||||
@ -46,7 +46,7 @@ end)
|
|||||||
minetest.after(60*59, update_mod_storage)
|
minetest.after(60*59, update_mod_storage)
|
||||||
|
|
||||||
-- Key2Number will be generated at runtine
|
-- Key2Number will be generated at runtine
|
||||||
local Key2Number = {}
|
local Key2Number = {}
|
||||||
|
|
||||||
local Name2Name = {} -- translation table
|
local Name2Name = {} -- translation table
|
||||||
|
|
||||||
@ -138,11 +138,12 @@ local function get_dest_node(pos, side)
|
|||||||
local _,node = Tube:get_node(pos)
|
local _,node = Tube:get_node(pos)
|
||||||
local dir = side_to_dir(side, node.param2)
|
local dir = side_to_dir(side, node.param2)
|
||||||
local spos, sdir = Tube:get_connected_node_pos(pos, dir)
|
local spos, sdir = Tube:get_connected_node_pos(pos, dir)
|
||||||
|
if not (spos and sdir) then return end
|
||||||
_,node = Tube:get_node(spos)
|
_,node = Tube:get_node(spos)
|
||||||
local out_side = dir_to_side(tubelib2.Turn180Deg[sdir], node.param2)
|
local out_side = dir_to_side(tubelib2.Turn180Deg[sdir], node.param2)
|
||||||
return spos, out_side, Name2Name[node.name] or node.name
|
return spos, out_side, Name2Name[node.name] or node.name
|
||||||
end
|
end
|
||||||
|
|
||||||
local function item_handling_node(name)
|
local function item_handling_node(name)
|
||||||
local node_def = name and tubelib_NodeDef[name]
|
local node_def = name and tubelib_NodeDef[name]
|
||||||
if node_def then
|
if node_def then
|
||||||
@ -153,7 +154,7 @@ end
|
|||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
-- API helper functions
|
-- API helper functions
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
-- Check the given list of numbers.
|
-- Check the given list of numbers.
|
||||||
-- Returns true if number(s) is/are valid and point to real nodes.
|
-- Returns true if number(s) is/are valid and point to real nodes.
|
||||||
function tubelib.check_numbers(numbers)
|
function tubelib.check_numbers(numbers)
|
||||||
@ -166,7 +167,7 @@ function tubelib.check_numbers(numbers)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function returns { pos, name } for the node on the given position number.
|
-- Function returns { pos, name } for the node on the given position number.
|
||||||
function tubelib.get_node_info(dest_num)
|
function tubelib.get_node_info(dest_num)
|
||||||
@ -174,7 +175,7 @@ function tubelib.get_node_info(dest_num)
|
|||||||
return Number2Pos[dest_num]
|
return Number2Pos[dest_num]
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function returns the node number from the given position or
|
-- Function returns the node number from the given position or
|
||||||
-- nil, if no node number for this position is assigned.
|
-- nil, if no node number for this position is assigned.
|
||||||
@ -188,14 +189,14 @@ function tubelib.get_node_number(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function is used for available nodes with lost numbers, only.
|
-- Function is used for available nodes with lost numbers, only.
|
||||||
function tubelib.get_new_number(pos, name)
|
function tubelib.get_new_number(pos, name)
|
||||||
-- store position
|
-- store position
|
||||||
local number = get_number(pos)
|
local number = get_number(pos)
|
||||||
Number2Pos[number] = {
|
Number2Pos[number] = {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
name = name,
|
name = name,
|
||||||
}
|
}
|
||||||
return number
|
return number
|
||||||
@ -225,7 +226,7 @@ end
|
|||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
-- Node construction/destruction functions
|
-- Node construction/destruction functions
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
-- Add node to the tubelib lists.
|
-- Add node to the tubelib lists.
|
||||||
-- Function determines and returns the node position number,
|
-- Function determines and returns the node position number,
|
||||||
-- needed for message communication.
|
-- needed for message communication.
|
||||||
@ -233,10 +234,10 @@ function tubelib.add_node(pos, name)
|
|||||||
if item_handling_node(name) then
|
if item_handling_node(name) then
|
||||||
Tube:after_place_node(pos)
|
Tube:after_place_node(pos)
|
||||||
end
|
end
|
||||||
-- store position
|
-- store position
|
||||||
local number = get_number(pos)
|
local number = get_number(pos)
|
||||||
Number2Pos[number] = {
|
Number2Pos[number] = {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
name = name,
|
name = name,
|
||||||
}
|
}
|
||||||
return number
|
return number
|
||||||
@ -249,7 +250,7 @@ function tubelib.remove_node(pos)
|
|||||||
if Number2Pos[number] then
|
if Number2Pos[number] then
|
||||||
name = Number2Pos[number].name
|
name = Number2Pos[number].name
|
||||||
Number2Pos[number] = {
|
Number2Pos[number] = {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
name = nil,
|
name = nil,
|
||||||
time = minetest.get_day_count() -- used for reservation timeout
|
time = minetest.get_day_count() -- used for reservation timeout
|
||||||
}
|
}
|
||||||
@ -284,11 +285,11 @@ function tubelib.register_node(name, add_names, node_definition)
|
|||||||
for _,n in ipairs(add_names) do
|
for _,n in ipairs(add_names) do
|
||||||
Name2Name[n] = name
|
Name2Name[n] = name
|
||||||
end
|
end
|
||||||
if node_definition.on_pull_item or node_definition.on_push_item or
|
if node_definition.on_pull_item or node_definition.on_push_item or
|
||||||
node_definition.is_pusher then
|
node_definition.is_pusher then
|
||||||
Tube:add_secondary_node_names({name})
|
Tube:add_secondary_node_names({name})
|
||||||
Tube:add_secondary_node_names(add_names)
|
Tube:add_secondary_node_names(add_names)
|
||||||
|
|
||||||
tubelib.KnownNodes[name] = true
|
tubelib.KnownNodes[name] = true
|
||||||
for _,n in ipairs(add_names) do
|
for _,n in ipairs(add_names) do
|
||||||
tubelib.KnownNodes[n] = true
|
tubelib.KnownNodes[n] = true
|
||||||
@ -319,7 +320,7 @@ function tubelib.send_message(numbers, placer_name, clicker_name, topic, payload
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function tubelib.send_request(number, topic, payload)
|
function tubelib.send_request(number, topic, payload)
|
||||||
if Number2Pos[number] and Number2Pos[number].name then
|
if Number2Pos[number] and Number2Pos[number].name then
|
||||||
@ -329,7 +330,7 @@ function tubelib.send_request(number, topic, payload)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- for defect nodes
|
-- for defect nodes
|
||||||
function tubelib.repair_node(pos)
|
function tubelib.repair_node(pos)
|
||||||
@ -358,10 +359,10 @@ function tubelib.push_items(pos, side, items, player_name)
|
|||||||
local npos, nside, name = get_dest_node(pos, side)
|
local npos, nside, name = get_dest_node(pos, side)
|
||||||
if npos == nil then return end
|
if npos == nil then return end
|
||||||
if tubelib_NodeDef[name] and tubelib_NodeDef[name].on_push_item then
|
if tubelib_NodeDef[name] and tubelib_NodeDef[name].on_push_item then
|
||||||
return tubelib_NodeDef[name].on_push_item(npos, nside, items, player_name)
|
return tubelib_NodeDef[name].on_push_item(npos, nside, items, player_name)
|
||||||
elseif name == "air" then
|
elseif name == "air" then
|
||||||
minetest.add_item(npos, items)
|
minetest.add_item(npos, items)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -374,7 +375,7 @@ function tubelib.unpull_items(pos, side, items, player_name)
|
|||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function tubelib.pull_stack(pos, side, player_name)
|
function tubelib.pull_stack(pos, side, player_name)
|
||||||
local npos, nside, name = get_dest_node(pos, side)
|
local npos, nside, name = get_dest_node(pos, side)
|
||||||
if npos == nil then return end
|
if npos == nil then return end
|
||||||
@ -425,7 +426,7 @@ function tubelib.get_this_item(meta, listname, list_number, num_items)
|
|||||||
if inv:is_empty(listname) then
|
if inv:is_empty(listname) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if num_items == nil then num_items = 1 end
|
if num_items == nil then num_items = 1 end
|
||||||
local items = inv:get_stack(listname, list_number)
|
local items = inv:get_stack(listname, list_number)
|
||||||
if items:get_count() > 0 then
|
if items:get_count() > 0 then
|
||||||
@ -480,7 +481,7 @@ function tubelib.get_stack(meta, listname)
|
|||||||
taken:set_count(taken:get_count() + 1)
|
taken:set_count(taken:get_count() + 1)
|
||||||
return taken
|
return taken
|
||||||
end
|
end
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return "full", "loaded", or "empty" depending
|
-- Return "full", "loaded", or "empty" depending
|
||||||
@ -499,7 +500,7 @@ function tubelib.fuelstate(meta, listname, item)
|
|||||||
return "loaded"
|
return "loaded"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return "full", "loaded", or "empty" depending
|
-- Return "full", "loaded", or "empty" depending
|
||||||
-- on the inventory load.
|
-- on the inventory load.
|
||||||
-- Full is returned, when no empty stack is available.
|
-- Full is returned, when no empty stack is available.
|
||||||
@ -553,8 +554,8 @@ local function data_maintenance()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.log("info", "[Tubelib] Data maintenance finished")
|
minetest.log("info", "[Tubelib] Data maintenance finished")
|
||||||
end
|
end
|
||||||
|
|
||||||
generate_Key2Number()
|
generate_Key2Number()
|
||||||
|
|
||||||
-- maintain data after 5 seconds
|
-- maintain data after 5 seconds
|
||||||
|
Loading…
Reference in New Issue
Block a user