summaryrefslogtreecommitdiff
path: root/pipeworks
diff options
context:
space:
mode:
Diffstat (limited to 'pipeworks')
-rw-r--r--pipeworks/autoplace_tubes.lua14
-rw-r--r--pipeworks/common.lua36
-rw-r--r--pipeworks/filter-injector.lua4
-rw-r--r--pipeworks/item_transport.lua25
-rw-r--r--pipeworks/luaentity.lua3
-rw-r--r--pipeworks/routing_tubes.lua25
-rw-r--r--pipeworks/sorting_tubes.lua2
-rw-r--r--pipeworks/textures/pipeworks_tube_broken_end.pngbin0 -> 1545 bytes
-rw-r--r--pipeworks/textures/pipeworks_tube_broken_inv.pngbin0 -> 923 bytes
-rw-r--r--pipeworks/textures/pipeworks_tube_broken_noctr.pngbin0 -> 1581 bytes
-rw-r--r--pipeworks/textures/pipeworks_tube_broken_plain.pngbin0 -> 1803 bytes
-rw-r--r--pipeworks/textures/pipeworks_tube_broken_short.pngbin0 -> 830 bytes
-rw-r--r--pipeworks/tube_registration.lua4
13 files changed, 82 insertions, 31 deletions
diff --git a/pipeworks/autoplace_tubes.lua b/pipeworks/autoplace_tubes.lua
index 280bd60..0d28e64 100644
--- a/pipeworks/autoplace_tubes.lua
+++ b/pipeworks/autoplace_tubes.lua
@@ -1,7 +1,7 @@
-- autorouting for pneumatic tubes
local function is_tube(nodename)
- return table.contains(pipeworks.tubenodes, nodename)
+ return pipeworks.table_contains(pipeworks.tubenodes, nodename)
end
--a function for determining which side of the node we are on
@@ -11,23 +11,23 @@ local function nodeside(node, tubedir)
end
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
return "back"
elseif back == -1 then
return "front"
end
- local topdir = minetest.facedir_to_top_dir(node.param2)
- local top = vector.dot(topdir, tubedir)
+ local topdir = pipeworks.facedir_to_top_dir(node.param2)
+ local top = pipeworks.vector_dot(topdir, tubedir)
if top == 1 then
return "top"
elseif top == -1 then
return "bottom"
end
- local rightdir = minetest.facedir_to_right_dir(node.param2)
- local right = vector.dot(rightdir, tubedir)
+ local rightdir = pipeworks.facedir_to_right_dir(node.param2)
+ local right = pipeworks.vector_dot(rightdir, tubedir)
if right == 1 then
return "right"
else
@@ -99,7 +99,7 @@ end
function pipeworks.scan_for_tube_objects(pos)
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
diff --git a/pipeworks/common.lua b/pipeworks/common.lua
index 1ee734f..5574bb2 100644
--- a/pipeworks/common.lua
+++ b/pipeworks/common.lua
@@ -2,7 +2,7 @@
-- Vector functions --
----------------------
-function vector.cross(a, b)
+function pipeworks.vector_cross(a, b)
return {
x = a.y * b.z - a.z * b.y,
y = a.z * b.x - a.x * b.z,
@@ -10,7 +10,7 @@ function vector.cross(a, b)
}
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
end
@@ -18,7 +18,7 @@ end
-- Facedir functions --
-----------------------
-function minetest.facedir_to_top_dir(facedir)
+function pipeworks.facedir_to_top_dir(facedir)
return ({[0] = {x = 0, y = 1, z = 0},
{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)]
end
-function minetest.facedir_to_right_dir(facedir)
- return vector.cross(
- minetest.facedir_to_top_dir(facedir),
+function pipeworks.facedir_to_right_dir(facedir)
+ return pipeworks.vector_cross(
+ pipeworks.facedir_to_top_dir(facedir),
minetest.facedir_to_dir(facedir)
)
end
-directions = {}
+local directions = {}
+pipeworks.directions = directions
function directions.side_to_dir(side)
return ({[0] = vector.new(),
vector.new( 0, 1, 0),
@@ -48,7 +49,7 @@ function directions.side_to_dir(side)
end
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]
end
@@ -56,7 +57,7 @@ end
-- String functions --
----------------------
---[[function string.split(str, sep)
+--[[function pipeworks.string_split(str, sep)
local fields = {}
local index = 1
local expr = "([^"..sep.."])+"
@@ -67,7 +68,7 @@ end
return fields
end]]
-function string.startswith(str, substr)
+function pipeworks.string_startswith(str, substr)
return str:sub(1, substr:len()) == substr
end
@@ -75,7 +76,7 @@ end
-- Table functions --
---------------------
-function table.contains(tbl, element)
+function pipeworks.table_contains(tbl, element)
for _, elt in pairs(tbl) do
if elt == element then
return true
@@ -84,7 +85,7 @@ function table.contains(tbl, element)
return false
end
-function table.extend(tbl, tbl2)
+function pipeworks.table_extend(tbl, tbl2)
local index = #tbl + 1
for _, elt in ipairs(tbl2) do
tbl[index] = elt
@@ -92,11 +93,11 @@ function table.extend(tbl, tbl2)
end
end
-function table.recursive_replace(tbl, pattern, replace_with)
+function pipeworks.table_recursive_replace(tbl, pattern, replace_with)
if type(tbl) == "table" then
local tbl2 = {}
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
return tbl2
elseif type(tbl) == "string" then
@@ -110,11 +111,12 @@ end
-- Formspec functions --
------------------------
-fs_helpers = {}
+local fs_helpers = {}
+pipeworks.fs_helpers = fs_helpers
function fs_helpers.on_receive_fields(pos, fields)
local meta = minetest.get_meta(pos)
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 new_value = tonumber(l[2])
local meta_name = l[3]
@@ -146,7 +148,7 @@ end
-- Env --
---------
-function minetest.load_position(pos)
+function pipeworks.load_position(pos)
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
if minetest.get_node_or_nil(pos) then
diff --git a/pipeworks/filter-injector.lua b/pipeworks/filter-injector.lua
index 72f7bad..0d22675 100644
--- a/pipeworks/filter-injector.lua
+++ b/pipeworks/filter-injector.lua
@@ -1,3 +1,5 @@
+local fs_helpers = pipeworks.fs_helpers
+
local function delay(x)
return (function() return x end)
end
@@ -169,7 +171,7 @@ local function punch_filter(data, filtpos, filtnode, msg)
is_fake_player = ":pipeworks",
get_wielded_item = delay(ItemStack(nil))
} -- 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 fromnode = minetest.get_node(frompos)
if not fromnode then return end
diff --git a/pipeworks/item_transport.lua b/pipeworks/item_transport.lua
index e906387..88df0d2 100644
--- a/pipeworks/item_transport.lua
+++ b/pipeworks/item_transport.lua
@@ -1,3 +1,6 @@
+local luaentity = pipeworks.luaentity
+local max_tube_limit = minetest.setting_get("pipeworks_max_tube_limit") or 30
+
function pipeworks.tube_item(pos, item)
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
end
@@ -29,6 +32,9 @@ function pipeworks.notvel(tbl, vel)
return tbl2
end
+local tube_last_times = {}
+local tube_item_count = {}
+
local function go_next(pos, velocity, stack)
local next_positions = {}
local max_priority = 0
@@ -55,7 +61,7 @@ local function go_next(pos, velocity, stack)
end
for _, vect in ipairs(can_go) do
local npos = vector.add(pos, vect)
- minetest.load_position(npos)
+ pipeworks.load_position(npos)
local node = minetest.get_node(npos)
local reg_node = minetest.registered_nodes[node.name]
if reg_node then
@@ -75,6 +81,21 @@ local function go_next(pos, velocity, stack)
end
end
+ local gt = minetest.get_gametime()
+ local h = minetest.hash_node_position(pos)
+ if tube_last_times[h] == gt then
+ local k = tube_item_count[h] or 0
+ if k > max_tube_limit then
+ -- Kill tube
+ minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
+ pipeworks.scan_for_tube_objects(pos)
+ end
+ tube_item_count[h] = k + 1
+ else
+ tube_last_times[h] = gt
+ tube_item_count[h] = 1
+ end
+
if not next_positions[1] then
return false, nil
end
@@ -225,7 +246,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
moved = true
end
- minetest.load_position(self.start_pos)
+ pipeworks.load_position(self.start_pos)
local node = minetest.get_node(self.start_pos)
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
local leftover
diff --git a/pipeworks/luaentity.lua b/pipeworks/luaentity.lua
index 50004ed..0105c91 100644
--- a/pipeworks/luaentity.lua
+++ b/pipeworks/luaentity.lua
@@ -1,6 +1,7 @@
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 = {}
diff --git a/pipeworks/routing_tubes.lua b/pipeworks/routing_tubes.lua
index 0a82fc8..17a3f79 100644
--- a/pipeworks/routing_tubes.lua
+++ b/pipeworks/routing_tubes.lua
@@ -9,6 +9,29 @@ minetest.register_craft( {
},
})
+pipeworks.register_tube("pipeworks:broken_tube", {
+ description = "Broken Tube (you hacker you)",
+ inventory_image = "pipeworks_tube_broken_inv.png",
+ plain = { { name = "pipeworks_tube_broken_plain.png", color = nodecolor, backface_culling = false } },
+ noctr = { { name = "pipeworks_tube_broken_plain.png", color = nodecolor, backface_culling = false } },
+ ends = { { name = "pipeworks_tube_broken_end.png", color = nodecolor } },
+ short = { name = "pipeworks_tube_broken_short.png", color = nodecolor },
+ node_def = {
+ drop = "pipeworks:tube_1",
+ groups = {not_in_creative_inventory = 1, tubedevice_receiver = 1},
+ tube = {
+ insert_object = function(pos, node, stack, direction)
+ minetest.item_drop(stack, nil, pos)
+ return ItemStack("")
+ end,
+ can_insert = function(pos,node,stack,direction)
+ return true
+ end,
+ priority = 50,
+ }
+ }
+})
+
-- the high priority tube is a low-cpu replacement for sorting tubes in situations
-- where players would use them for simple routing (turning off paths)
-- without doing actual sorting, like at outputs of tubedevices that might both accept and eject items
@@ -101,7 +124,7 @@ if pipeworks.enable_one_way_tube then
return {velocity}
end,
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)
end,
priority = 75 -- Higher than normal tubes, but lower than receivers
diff --git a/pipeworks/sorting_tubes.lua b/pipeworks/sorting_tubes.lua
index edaa24a..0d6ec2a 100644
--- a/pipeworks/sorting_tubes.lua
+++ b/pipeworks/sorting_tubes.lua
@@ -1,3 +1,5 @@
+local fs_helpers = pipeworks.fs_helpers
+
if pipeworks.enable_mese_tube then
local function update_formspec(pos)
local meta = minetest.get_meta(pos)
diff --git a/pipeworks/textures/pipeworks_tube_broken_end.png b/pipeworks/textures/pipeworks_tube_broken_end.png
new file mode 100644
index 0000000..1829f8c
--- /dev/null
+++ b/pipeworks/textures/pipeworks_tube_broken_end.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_tube_broken_inv.png b/pipeworks/textures/pipeworks_tube_broken_inv.png
new file mode 100644
index 0000000..5b8d707
--- /dev/null
+++ b/pipeworks/textures/pipeworks_tube_broken_inv.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_tube_broken_noctr.png b/pipeworks/textures/pipeworks_tube_broken_noctr.png
new file mode 100644
index 0000000..a17da5f
--- /dev/null
+++ b/pipeworks/textures/pipeworks_tube_broken_noctr.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_tube_broken_plain.png b/pipeworks/textures/pipeworks_tube_broken_plain.png
new file mode 100644
index 0000000..7957e59
--- /dev/null
+++ b/pipeworks/textures/pipeworks_tube_broken_plain.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_tube_broken_short.png b/pipeworks/textures/pipeworks_tube_broken_short.png
new file mode 100644
index 0000000..237fec5
--- /dev/null
+++ b/pipeworks/textures/pipeworks_tube_broken_short.png
Binary files differ
diff --git a/pipeworks/tube_registration.lua b/pipeworks/tube_registration.lua
index c926216..c720755 100644
--- a/pipeworks/tube_registration.lua
+++ b/pipeworks/tube_registration.lua
@@ -44,7 +44,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
end
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])
outimgs[vti[v]] = noctrs[v]
end
@@ -127,7 +127,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
nodedef.tube[key] = val
end
else
- nodedef[key] = table.recursive_replace(value, "#id", tname)
+ nodedef[key] = pipeworks.table_recursive_replace(value, "#id", tname)
end
end