forked from mtcontrib/pipeworks
Namespace pollution cleanup (Used list at #154)
This commit is contained in:
parent
0639bb9706
commit
0056116148
@ -1,7 +1,7 @@
|
|||||||
-- autorouting for pneumatic tubes
|
-- autorouting for pneumatic tubes
|
||||||
|
|
||||||
local function is_tube(nodename)
|
local function is_tube(nodename)
|
||||||
return table.contains(pipeworks.tubenodes, nodename)
|
return pipeworks.table_contains(pipeworks.tubenodes, nodename)
|
||||||
end
|
end
|
||||||
|
|
||||||
--a function for determining which side of the node we are on
|
--a function for determining which side of the node we are on
|
||||||
@ -11,23 +11,23 @@ local function nodeside(node, tubedir)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local backdir = minetest.facedir_to_dir(node.param2)
|
local backdir = minetest.facedir_to_dir(node.param2)
|
||||||
local back = vector.dot(backdir, tubedir)
|
local back = pipeworks.vector_dot(backdir, tubedir)
|
||||||
if back == 1 then
|
if back == 1 then
|
||||||
return "back"
|
return "back"
|
||||||
elseif back == -1 then
|
elseif back == -1 then
|
||||||
return "front"
|
return "front"
|
||||||
end
|
end
|
||||||
|
|
||||||
local topdir = minetest.facedir_to_top_dir(node.param2)
|
local topdir = pipeworks.facedir_to_top_dir(node.param2)
|
||||||
local top = vector.dot(topdir, tubedir)
|
local top = pipeworks.vector_dot(topdir, tubedir)
|
||||||
if top == 1 then
|
if top == 1 then
|
||||||
return "top"
|
return "top"
|
||||||
elseif top == -1 then
|
elseif top == -1 then
|
||||||
return "bottom"
|
return "bottom"
|
||||||
end
|
end
|
||||||
|
|
||||||
local rightdir = minetest.facedir_to_right_dir(node.param2)
|
local rightdir = pipeworks.facedir_to_right_dir(node.param2)
|
||||||
local right = vector.dot(rightdir, tubedir)
|
local right = pipeworks.vector_dot(rightdir, tubedir)
|
||||||
if right == 1 then
|
if right == 1 then
|
||||||
return "right"
|
return "right"
|
||||||
else
|
else
|
||||||
@ -99,7 +99,7 @@ end
|
|||||||
|
|
||||||
function pipeworks.scan_for_tube_objects(pos)
|
function pipeworks.scan_for_tube_objects(pos)
|
||||||
for side = 0, 6 do
|
for side = 0, 6 do
|
||||||
tube_autoroute(vector.add(pos, directions.side_to_dir(side)))
|
tube_autoroute(vector.add(pos, pipeworks.directions.side_to_dir(side)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
36
common.lua
36
common.lua
@ -2,7 +2,7 @@
|
|||||||
-- Vector functions --
|
-- Vector functions --
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
function vector.cross(a, b)
|
function pipeworks.vector_cross(a, b)
|
||||||
return {
|
return {
|
||||||
x = a.y * b.z - a.z * b.y,
|
x = a.y * b.z - a.z * b.y,
|
||||||
y = a.z * b.x - a.x * b.z,
|
y = a.z * b.x - a.x * b.z,
|
||||||
@ -10,7 +10,7 @@ function vector.cross(a, b)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.dot(a, b)
|
function pipeworks.vector_dot(a, b)
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z
|
return a.x * b.x + a.y * b.y + a.z * b.z
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ end
|
|||||||
-- Facedir functions --
|
-- Facedir functions --
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
function minetest.facedir_to_top_dir(facedir)
|
function pipeworks.facedir_to_top_dir(facedir)
|
||||||
return ({[0] = {x = 0, y = 1, z = 0},
|
return ({[0] = {x = 0, y = 1, z = 0},
|
||||||
{x = 0, y = 0, z = 1},
|
{x = 0, y = 0, z = 1},
|
||||||
{x = 0, y = 0, z = -1},
|
{x = 0, y = 0, z = -1},
|
||||||
@ -28,14 +28,15 @@ function minetest.facedir_to_top_dir(facedir)
|
|||||||
[math.floor(facedir / 4)]
|
[math.floor(facedir / 4)]
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.facedir_to_right_dir(facedir)
|
function pipeworks.facedir_to_right_dir(facedir)
|
||||||
return vector.cross(
|
return pipeworks.vector_cross(
|
||||||
minetest.facedir_to_top_dir(facedir),
|
pipeworks.facedir_to_top_dir(facedir),
|
||||||
minetest.facedir_to_dir(facedir)
|
minetest.facedir_to_dir(facedir)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
directions = {}
|
local directions = {}
|
||||||
|
pipeworks.directions = directions
|
||||||
function directions.side_to_dir(side)
|
function directions.side_to_dir(side)
|
||||||
return ({[0] = vector.new(),
|
return ({[0] = vector.new(),
|
||||||
vector.new( 0, 1, 0),
|
vector.new( 0, 1, 0),
|
||||||
@ -48,7 +49,7 @@ function directions.side_to_dir(side)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function directions.dir_to_side(dir)
|
function directions.dir_to_side(dir)
|
||||||
local c = vector.dot(dir, vector.new(1, 2, 3)) + 4
|
local c = pipeworks.vector_dot(dir, vector.new(1, 2, 3)) + 4
|
||||||
return ({6, 2, 4, 0, 3, 1, 5})[c]
|
return ({6, 2, 4, 0, 3, 1, 5})[c]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ end
|
|||||||
-- String functions --
|
-- String functions --
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
--[[function string.split(str, sep)
|
--[[function pipeworks.string_split(str, sep)
|
||||||
local fields = {}
|
local fields = {}
|
||||||
local index = 1
|
local index = 1
|
||||||
local expr = "([^"..sep.."])+"
|
local expr = "([^"..sep.."])+"
|
||||||
@ -67,7 +68,7 @@ end
|
|||||||
return fields
|
return fields
|
||||||
end]]
|
end]]
|
||||||
|
|
||||||
function string.startswith(str, substr)
|
function pipeworks.string_startswith(str, substr)
|
||||||
return str:sub(1, substr:len()) == substr
|
return str:sub(1, substr:len()) == substr
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ end
|
|||||||
-- Table functions --
|
-- Table functions --
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
function table.contains(tbl, element)
|
function pipeworks.table_contains(tbl, element)
|
||||||
for _, elt in pairs(tbl) do
|
for _, elt in pairs(tbl) do
|
||||||
if elt == element then
|
if elt == element then
|
||||||
return true
|
return true
|
||||||
@ -84,7 +85,7 @@ function table.contains(tbl, element)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function table.extend(tbl, tbl2)
|
function pipeworks.table_extend(tbl, tbl2)
|
||||||
local index = #tbl + 1
|
local index = #tbl + 1
|
||||||
for _, elt in ipairs(tbl2) do
|
for _, elt in ipairs(tbl2) do
|
||||||
tbl[index] = elt
|
tbl[index] = elt
|
||||||
@ -92,11 +93,11 @@ function table.extend(tbl, tbl2)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function table.recursive_replace(tbl, pattern, replace_with)
|
function pipeworks.table_recursive_replace(tbl, pattern, replace_with)
|
||||||
if type(tbl) == "table" then
|
if type(tbl) == "table" then
|
||||||
local tbl2 = {}
|
local tbl2 = {}
|
||||||
for key, value in pairs(tbl) do
|
for key, value in pairs(tbl) do
|
||||||
tbl2[key] = table.recursive_replace(value, pattern, replace_with)
|
tbl2[key] = pipeworks.table_recursive_replace(value, pattern, replace_with)
|
||||||
end
|
end
|
||||||
return tbl2
|
return tbl2
|
||||||
elseif type(tbl) == "string" then
|
elseif type(tbl) == "string" then
|
||||||
@ -110,11 +111,12 @@ end
|
|||||||
-- Formspec functions --
|
-- Formspec functions --
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
fs_helpers = {}
|
local fs_helpers = {}
|
||||||
|
pipeworks.fs_helpers = fs_helpers
|
||||||
function fs_helpers.on_receive_fields(pos, fields)
|
function fs_helpers.on_receive_fields(pos, fields)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
for field, value in pairs(fields) do
|
for field, value in pairs(fields) do
|
||||||
if field:startswith("fs_helpers_cycling:") then
|
if pipeworks.string_startswith(field, "fs_helpers_cycling:") then
|
||||||
local l = field:split(":")
|
local l = field:split(":")
|
||||||
local new_value = tonumber(l[2])
|
local new_value = tonumber(l[2])
|
||||||
local meta_name = l[3]
|
local meta_name = l[3]
|
||||||
@ -146,7 +148,7 @@ end
|
|||||||
-- Env --
|
-- Env --
|
||||||
---------
|
---------
|
||||||
|
|
||||||
function minetest.load_position(pos)
|
function pipeworks.load_position(pos)
|
||||||
if pos.x < -30912 or pos.y < -30912 or pos.z < -30912 or
|
if pos.x < -30912 or pos.y < -30912 or pos.z < -30912 or
|
||||||
pos.x > 30927 or pos.y > 30927 or pos.z > 30927 then return end
|
pos.x > 30927 or pos.y > 30927 or pos.z > 30927 then return end
|
||||||
if minetest.get_node_or_nil(pos) then
|
if minetest.get_node_or_nil(pos) then
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
local fs_helpers = pipeworks.fs_helpers
|
||||||
|
|
||||||
local function delay(x)
|
local function delay(x)
|
||||||
return (function() return x end)
|
return (function() return x end)
|
||||||
end
|
end
|
||||||
@ -169,7 +171,7 @@ local function punch_filter(data, filtpos, filtnode, msg)
|
|||||||
is_fake_player = ":pipeworks",
|
is_fake_player = ":pipeworks",
|
||||||
get_wielded_item = delay(ItemStack(nil))
|
get_wielded_item = delay(ItemStack(nil))
|
||||||
} -- TODO: use a mechanism as the wielder one
|
} -- TODO: use a mechanism as the wielder one
|
||||||
local dir = minetest.facedir_to_right_dir(filtnode.param2)
|
local dir = pipeworks.facedir_to_right_dir(filtnode.param2)
|
||||||
local frompos = vector.subtract(filtpos, dir)
|
local frompos = vector.subtract(filtpos, dir)
|
||||||
local fromnode = minetest.get_node(frompos)
|
local fromnode = minetest.get_node(frompos)
|
||||||
if not fromnode then return end
|
if not fromnode then return end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
local luaentity = pipeworks.luaentity
|
||||||
|
|
||||||
function pipeworks.tube_item(pos, item)
|
function pipeworks.tube_item(pos, item)
|
||||||
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
|
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
|
||||||
end
|
end
|
||||||
@ -55,7 +57,7 @@ local function go_next(pos, velocity, stack)
|
|||||||
end
|
end
|
||||||
for _, vect in ipairs(can_go) do
|
for _, vect in ipairs(can_go) do
|
||||||
local npos = vector.add(pos, vect)
|
local npos = vector.add(pos, vect)
|
||||||
minetest.load_position(npos)
|
pipeworks.load_position(npos)
|
||||||
local node = minetest.get_node(npos)
|
local node = minetest.get_node(npos)
|
||||||
local reg_node = minetest.registered_nodes[node.name]
|
local reg_node = minetest.registered_nodes[node.name]
|
||||||
if reg_node then
|
if reg_node then
|
||||||
@ -225,7 +227,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
|||||||
moved = true
|
moved = true
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.load_position(self.start_pos)
|
pipeworks.load_position(self.start_pos)
|
||||||
local node = minetest.get_node(self.start_pos)
|
local node = minetest.get_node(self.start_pos)
|
||||||
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
|
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
|
||||||
local leftover
|
local leftover
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
local max_entity_id = 1000000000000 -- If you need more, there's a problem with your code
|
local max_entity_id = 1000000000000 -- If you need more, there's a problem with your code
|
||||||
|
|
||||||
luaentity = {}
|
local luaentity = {}
|
||||||
|
pipeworks.luaentity = luaentity
|
||||||
|
|
||||||
luaentity.registered_entities = {}
|
luaentity.registered_entities = {}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ if pipeworks.enable_one_way_tube then
|
|||||||
return {velocity}
|
return {velocity}
|
||||||
end,
|
end,
|
||||||
can_insert = function(pos, node, stack, direction)
|
can_insert = function(pos, node, stack, direction)
|
||||||
local dir = minetest.facedir_to_right_dir(node.param2)
|
local dir = pipeworks.facedir_to_right_dir(node.param2)
|
||||||
return vector.equals(dir, direction)
|
return vector.equals(dir, direction)
|
||||||
end,
|
end,
|
||||||
priority = 75 -- Higher than normal tubes, but lower than receivers
|
priority = 75 -- Higher than normal tubes, but lower than receivers
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
local fs_helpers = pipeworks.fs_helpers
|
||||||
|
|
||||||
if pipeworks.enable_mese_tube then
|
if pipeworks.enable_mese_tube then
|
||||||
local function update_formspec(pos)
|
local function update_formspec(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
@ -44,7 +44,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
|
|||||||
end
|
end
|
||||||
|
|
||||||
for _, v in ipairs(connects) do
|
for _, v in ipairs(connects) do
|
||||||
table.extend(outboxes, pipeworks.tube_boxes[v])
|
pipeworks.table_extend(outboxes, pipeworks.tube_boxes[v])
|
||||||
table.insert(outsel, pipeworks.tube_selectboxes[v])
|
table.insert(outsel, pipeworks.tube_selectboxes[v])
|
||||||
outimgs[vti[v]] = noctrs[v]
|
outimgs[vti[v]] = noctrs[v]
|
||||||
end
|
end
|
||||||
@ -127,7 +127,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
|
|||||||
nodedef.tube[key] = val
|
nodedef.tube[key] = val
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nodedef[key] = table.recursive_replace(value, "#id", tname)
|
nodedef[key] = pipeworks.table_recursive_replace(value, "#id", tname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user