summaryrefslogtreecommitdiff
path: root/pipeworks
diff options
context:
space:
mode:
Diffstat (limited to 'pipeworks')
-rw-r--r--pipeworks/LICENSE191
-rw-r--r--pipeworks/compat-chests.lua13
-rw-r--r--pipeworks/default_settings.lua2
-rw-r--r--pipeworks/filter-injector.lua95
-rw-r--r--pipeworks/init.lua2
-rw-r--r--pipeworks/item_transport.lua11
-rw-r--r--pipeworks/lua_tube.lua850
-rw-r--r--pipeworks/models.lua4
-rw-r--r--pipeworks/settingtypes.txt9
-rw-r--r--pipeworks/signal_tubes.lua83
-rw-r--r--pipeworks/textures/pipeworks_digiline_conductor_tube_end.pngbin0 -> 174 bytes
-rw-r--r--pipeworks/textures/pipeworks_digiline_conductor_tube_inv.pngbin0 -> 337 bytes
-rw-r--r--pipeworks/textures/pipeworks_digiline_conductor_tube_noctr.pngbin0 -> 179 bytes
-rw-r--r--pipeworks/textures/pipeworks_digiline_conductor_tube_plain.pngbin0 -> 169 bytes
-rw-r--r--pipeworks/textures/pipeworks_digiline_conductor_tube_short.pngbin0 -> 162 bytes
-rw-r--r--pipeworks/textures/pipeworks_lua_tube_port_burnt.pngbin0 -> 178 bytes
-rw-r--r--pipeworks/textures/pipeworks_lua_tube_port_off.pngbin0 -> 178 bytes
-rw-r--r--pipeworks/textures/pipeworks_lua_tube_port_on.pngbin0 -> 178 bytes
18 files changed, 1230 insertions, 30 deletions
diff --git a/pipeworks/LICENSE b/pipeworks/LICENSE
index 4362b49..ecbf212 100644
--- a/pipeworks/LICENSE
+++ b/pipeworks/LICENSE
@@ -500,3 +500,194 @@ necessary. Here is a sample; alter the names:
Ty Coon, President of Vice
That's all there is to it!
+
+
+--------------------------------------------------------------------------------
+
+Some code in lua_tube.lua is copied from The Mesecons Mod for Minetest:
+
+License of source code
+----------------------
+Copyright (C) 2011-2016 Mesecons Mod Developer Team and contributors
+
+This program is free software; you can redistribute the Mesecons Mod and/or
+modify it under the terms of the GNU Lesser General Public License version 3
+published by the Free Software Foundation.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this library; if not, write to the
+Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+Boston, MA 02110-1301, USA.
+
+
+GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
diff --git a/pipeworks/compat-chests.lua b/pipeworks/compat-chests.lua
index 7cff6fd..69eb2f1 100644
--- a/pipeworks/compat-chests.lua
+++ b/pipeworks/compat-chests.lua
@@ -36,7 +36,7 @@ local function get_chest_formspec(pos)
pipeworks.button_on
}
)..pipeworks.button_label
-
+
return formspec
end
@@ -62,7 +62,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local sound = open_chests[pn].sound
local swap = open_chests[pn].swap
local node = minetest.get_node(pos)
-
+
open_chests[pn] = nil
for k, v in pairs(open_chests) do
if v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z then
@@ -71,13 +71,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
minetest.after(0.2, function()
minetest.swap_node(pos, { name = "default:" .. swap, param2 = node.param2 })
-
+
-- Pipeworks notification
pipeworks.after_place(pos)
end)
minetest.sound_play(sound, {gain = 0.3, pos = pos, max_hear_distance = 10})
end
-
+
-- Pipeworks Switch
if pipeworks.may_configure(pos, player) and not fields.quit then
fs_helpers.on_receive_fields(pos, fields)
@@ -142,6 +142,7 @@ override_protected = {
end
return inv:room_for_item("main", stack)
end,
+ input_inventory = "main",
connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
},
after_dig_node = pipeworks.after_dig
@@ -191,9 +192,9 @@ override = {
after_dig_node = pipeworks.after_dig
}
--[[local override_common = {
-
+
}
-for k,v in pairs(override_common) do
+for k,v in pairs(override_common) do
override_protected[k] = v
override[k] = v
end]]
diff --git a/pipeworks/default_settings.lua b/pipeworks/default_settings.lua
index 99b86fe..91e511c 100644
--- a/pipeworks/default_settings.lua
+++ b/pipeworks/default_settings.lua
@@ -15,12 +15,14 @@ local settings = {
enable_detector_tube = true,
enable_digiline_detector_tube = true,
enable_conductor_tube = true,
+ enable_digiline_conductor_tube = true,
enable_accelerator_tube = true,
enable_crossing_tube = true,
enable_sand_tube = true,
enable_mese_sand_tube = true,
enable_one_way_tube = true,
enable_priority_tube = true,
+ enable_lua_tube = true,
enable_cyclic_mode = true,
drop_on_routing_fail = false,
diff --git a/pipeworks/filter-injector.lua b/pipeworks/filter-injector.lua
index 45b27c4..c9d132f 100644
--- a/pipeworks/filter-injector.lua
+++ b/pipeworks/filter-injector.lua
@@ -156,7 +156,7 @@ local function grabAndFire(data,slotseq_mode,exmatch_mode,filtmeta,frominv,fromi
end
local pos = vector.add(frompos, vector.multiply(dir, 1.4))
local start_pos = vector.add(frompos, dir)
- local item1 = pipeworks.tube_inject_item(pos, start_pos, dir, item)
+ local item1 = pipeworks.tube_inject_item(pos, start_pos, dir, item, fakePlayer:get_player_name())
return true-- only fire one item, please
end
end
@@ -219,7 +219,7 @@ local function punch_filter(data, filtpos, filtnode, msg)
local filters = {}
if data.digiline then
local function add_filter(name, group, count, wear, metadata)
- table.insert(filters, {name = name, group = group, count = count, wear = wear, metadata = metadata})
+ table.insert(filters, {name = name, group = group, count = tonumber(count), wear = wear, metadata = metadata})
end
local function add_itemstring_filter(filter)
@@ -317,8 +317,16 @@ local function punch_filter(data, filtpos, filtnode, msg)
exact_match = filtmeta:get_int("exmatch_mode")
end
- local frommeta = minetest.get_meta(frompos)
- local frominv = frommeta:get_inventory()
+ local frominv
+ if fromtube.return_input_invref then
+ frominv = fromtube.return_input_invref(frompos, fromnode, dir, owner)
+ if not frominv then
+ return
+ end
+ else
+ local frommeta = minetest.get_meta(frompos)
+ frominv = frommeta:get_inventory()
+ end
if fromtube.before_filter then fromtube.before_filter(frompos) end
for _, frominvname in ipairs(type(fromtube.input_inventory) == "table" and fromtube.input_inventory or {fromtube.input_inventory}) do
local done = false
@@ -378,12 +386,22 @@ for _, data in ipairs({
end,
after_dig_node = pipeworks.after_dig,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- if not pipeworks.may_configure(pos, player) then return 0 end
- return stack:get_count()
+ if not pipeworks.may_configure(pos, player) then
+ return 0
+ end
+ local inv = minetest.get_meta(pos):get_inventory()
+ inv:set_stack("main", index, stack)
+ return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- if not pipeworks.may_configure(pos, player) then return 0 end
- return stack:get_count()
+ if not pipeworks.may_configure(pos, player) then
+ return 0
+ end
+ local inv = minetest.get_meta(pos):get_inventory()
+ local fake_stack = inv:get_stack("main", index)
+ fake_stack:take_item(stack:get_count())
+ inv:set_stack("main", index, fake_stack)
+ return 0
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
if not pipeworks.may_configure(pos, player) then return 0 end
@@ -481,3 +499,64 @@ if minetest.get_modpath("digilines") then
},
})
end
+
+--[[
+In the past the filter-injectors had real items in their inventories. This code
+puts them to the input to the filter-injector if possible. Else the items are
+dropped.
+]]
+local function put_to_inputinv(pos, node, filtmeta, list)
+ local dir = pipeworks.facedir_to_right_dir(node.param2)
+ local frompos = vector.subtract(pos, dir)
+ local fromnode = minetest.get_node(frompos)
+ local fromdef = minetest.registered_nodes[fromnode.name]
+ if not fromdef or not fromdef.tube then
+ return
+ end
+ local fromtube = fromdef.tube
+ local frominv
+ if fromtube.return_input_invref then
+ local owner = filtmeta:get_string("owner")
+ frominv = fromtube.return_input_invref(frompos, fromnode, dir, owner)
+ if not frominv then
+ return
+ end
+ else
+ frominv = minetest.get_meta(frompos):get_inventory()
+ end
+ local listname = type(fromtube.input_inventory) == "table" and
+ fromtube.input_inventory[1] or fromtube.input_inventory
+ if not listname then
+ return
+ end
+ for i = 1, #list do
+ local item = list[i]
+ if not item:is_empty() then
+ local leftover = frominv:add_item(listname, item)
+ if not leftover:is_empty() then
+ minetest.add_item(pos, leftover)
+ end
+ end
+ end
+ return true
+end
+minetest.register_lbm({
+ label = "Give back items of old filters that had real inventories",
+ name = "pipeworks:give_back_old_filter_items",
+ nodenames = {"pipeworks:filter", "pipeworks:mese_filter"},
+ run_at_every_load = false,
+ action = function(pos, node)
+ local meta = minetest.get_meta(pos)
+ local list = meta:get_inventory():get_list("main")
+ if put_to_inputinv(pos, node, meta, list) then
+ return
+ end
+ pos.y = pos.y + 1
+ for i = 1, #list do
+ local item = list[i]
+ if not item:is_empty() then
+ minetest.add_item(pos, item)
+ end
+ end
+ end,
+})
diff --git a/pipeworks/init.lua b/pipeworks/init.lua
index a3f31c7..2e05337 100644
--- a/pipeworks/init.lua
+++ b/pipeworks/init.lua
@@ -38,6 +38,7 @@ pipeworks.rules_all = {{x=0, y=0, z=1},{x=0, y=0, z=-1},{x=1, y=0, z=0},{x=-1, y
{x=0, y=1, z=0}, {x=0, y=-1, z=0}}
pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
+pipeworks.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
pipeworks.liquid_texture = "default_water.png"
@@ -118,6 +119,7 @@ if pipeworks.enable_redefines then
dofile(pipeworks.modpath.."/compat-furnaces.lua")
end
if pipeworks.enable_autocrafter then dofile(pipeworks.modpath.."/autocrafter.lua") end
+if pipeworks.enable_lua_tube then dofile(pipeworks.modpath.."/lua_tube.lua") end
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
diff --git a/pipeworks/item_transport.lua b/pipeworks/item_transport.lua
index b2d2aa2..551db07 100644
--- a/pipeworks/item_transport.lua
+++ b/pipeworks/item_transport.lua
@@ -7,13 +7,14 @@ function pipeworks.tube_item(pos, item)
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
end
-function pipeworks.tube_inject_item(pos, start_pos, velocity, item)
+function pipeworks.tube_inject_item(pos, start_pos, velocity, item, owner)
-- Take item in any format
local stack = ItemStack(item)
local obj = luaentity.add_entity(pos, "pipeworks:tubed_item")
obj:set_item(stack:to_string())
obj.start_pos = vector.new(start_pos)
obj:setvelocity(velocity)
+ obj.owner = owner
--obj:set_color("red") -- todo: this is test-only code
return obj
end
@@ -49,7 +50,7 @@ minetest.register_globalstep(function(dtime)
end
end)
-local function go_next(pos, velocity, stack)
+local function go_next(pos, velocity, stack, owner)
local next_positions = {}
local max_priority = 0
local cnode = minetest.get_node(pos)
@@ -84,7 +85,7 @@ local function go_next(pos, velocity, stack)
local tube_priority = (tube_def and tube_def.priority) or 100
if tubedevice > 0 and tube_priority >= max_priority then
if not tube_def or not tube_def.can_insert or
- tube_def.can_insert(npos, node, stack, vect) then
+ tube_def.can_insert(npos, node, stack, vect, owner) then
if tube_priority > max_priority then
max_priority = tube_priority
next_positions = {}
@@ -260,7 +261,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
local leftover
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
- leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos, node, stack, vel)
+ leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos, node, stack, vel, self.owner)
else
leftover = stack
end
@@ -276,7 +277,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
end
if moved then
- local found_next, new_velocity = go_next(self.start_pos, velocity, stack) -- todo: color
+ local found_next, new_velocity = go_next(self.start_pos, velocity, stack, self.owner) -- todo: color
local rev_vel = vector.multiply(velocity, -1)
local rev_dir = vector.direction(self.start_pos,vector.add(self.start_pos,rev_vel))
local rev_node = minetest.get_node(vector.round(vector.add(self.start_pos,rev_dir)))
diff --git a/pipeworks/lua_tube.lua b/pipeworks/lua_tube.lua
new file mode 100644
index 0000000..51665ae
--- /dev/null
+++ b/pipeworks/lua_tube.lua
@@ -0,0 +1,850 @@
+-- ______
+-- |
+-- |
+-- | __ ___ _ __ _ _
+-- | | | | | |\ | | |_| | | | | |_ |_|
+-- |___| |______ |__| | \| | | \ |__| |_ |_ |_ |\ tube
+-- |
+-- |
+--
+
+-- Reference
+-- ports = get_real_port_states(pos): gets if inputs are powered from outside
+-- newport = merge_port_states(state1, state2): just does result = state1 or state2 for every port
+-- set_port(pos, rule, state): activates/deactivates the mesecons according to the port states
+-- set_port_states(pos, ports): Applies new port states to a Luacontroller at pos
+-- run(pos): runs the code in the controller at pos
+-- reset_meta(pos, code, errmsg): performs a software-reset, installs new code and prints error messages
+-- resetn(pos): performs a hardware reset, turns off all ports
+--
+-- The Sandbox
+-- The whole code of the controller runs in a sandbox,
+-- a very restricted environment.
+-- Actually the only way to damage the server is to
+-- use too much memory from the sandbox.
+-- You can add more functions to the environment
+-- (see where local env is defined)
+-- Something nice to play is is appending minetest.env to it.
+
+local BASENAME = "pipeworks:lua_tube"
+
+local rules = {
+ red = {x = -1, y = 0, z = 0, name = "red"},
+ blue = {x = 1, y = 0, z = 0, name = "blue"},
+ yellow = {x = 0, y = -1, z = 0, name = "yellow"},
+ green = {x = 0, y = 1, z = 0, name = "green"},
+ black = {x = 0, y = 0, z = -1, name = "black"},
+ white = {x = 0, y = 0, z = 1, name = "white"},
+}
+
+
+------------------
+-- Action stuff --
+------------------
+-- These helpers are required to set the port states of the lua_tube
+
+local function update_real_port_states(pos, rule_name, new_state)
+ local meta = minetest.get_meta(pos)
+ if rule_name == nil then
+ meta:set_int("real_portstates", 1)
+ return
+ end
+ local n = meta:get_int("real_portstates") - 1
+ local L = {}
+ for i = 1, 6 do
+ L[i] = n % 2
+ n = math.floor(n / 2)
+ end
+ -- (0,0,-1) (0,-1,0) (-1,0,0) (1,0,0) (0,1,0) (0,0,1)
+ local pos_to_side = { 5, 3, 1, nil, 2, 4, 6 }
+ if rule_name.x == nil then
+ for _, rname in ipairs(rule_name) do
+ local port = pos_to_side[rname.x + (2 * rname.y) + (3 * rname.z) + 4]
+ L[port] = (newstate == "on") and 1 or 0
+ end
+ else
+ local port = pos_to_side[rule_name.x + (2 * rule_name.y) + (3 * rule_name.z) + 4]
+ L[port] = (new_state == "on") and 1 or 0
+ end
+ meta:set_int("real_portstates",
+ 1 +
+ 1 * L[1] +
+ 2 * L[2] +
+ 4 * L[3] +
+ 8 * L[4] +
+ 16 * L[5] +
+ 32 * L[6])
+end
+
+
+local port_names = {"red", "blue", "yellow", "green", "black", "white"}
+
+local function get_real_port_states(pos)
+ -- Determine if ports are powered (by itself or from outside)
+ local meta = minetest.get_meta(pos)
+ local L = {}
+ local n = meta:get_int("real_portstates") - 1
+ for _, name in ipairs(port_names) do
+ L[name] = ((n % 2) == 1)
+ n = math.floor(n / 2)
+ end
+ return L
+end
+
+
+local function merge_port_states(ports, vports)
+ return {
+ red = ports.red or vports.red,
+ blue = ports.blue or vports.blue,
+ yellow = ports.yellow or vports.yellow,
+ green = ports.green or vports.green,
+ black = ports.black or vports.black,
+ white = ports.white or vports.white,
+ }
+end
+
+local function generate_name(ports)
+ local red = ports.red and 1 or 0
+ local blue = ports.blue and 1 or 0
+ local yellow = ports.yellow and 1 or 0
+ local green = ports.green and 1 or 0
+ local black = ports.black and 1 or 0
+ local white = ports.white and 1 or 0
+ return BASENAME..white..black..green..yellow..blue..red
+end
+
+
+local function set_port(pos, rule, state)
+ if state then
+ mesecon.receptor_on(pos, {rule})
+ else
+ mesecon.receptor_off(pos, {rule})
+ end
+end
+
+
+local function clean_port_states(ports)
+ ports.red = ports.red and true or false
+ ports.blue = ports.blue and true or false
+ ports.yellow = ports.yellow and true or false
+ ports.green = ports.green and true or false
+ ports.black = ports.black and true or false
+ ports.white = ports.white and true or false
+end
+
+
+local function set_port_states(pos, ports)
+ local node = minetest.get_node(pos)
+ local name = node.name
+ clean_port_states(ports)
+ local vports = minetest.registered_nodes[name].virtual_portstates
+ local new_name = generate_name(ports)
+
+ if name ~= new_name and vports then
+ -- Problem:
+ -- We need to place the new node first so that when turning
+ -- off some port, it won't stay on because the rules indicate
+ -- there is an onstate output port there.
+ -- When turning the output off then, it will however cause feedback
+ -- so that the lua_tube will receive an "off" event by turning
+ -- its output off.
+ -- Solution / Workaround:
+ -- Remember which output was turned off and ignore next "off" event.
+ local meta = minetest.get_meta(pos)
+ local ign = minetest.deserialize(meta:get_string("ignore_offevents")) or {}
+ if ports.red and not vports.red and not mesecon.is_powered(pos, rules.red) then ign.red = true end
+ if ports.blue and not vports.blue and not mesecon.is_powered(pos, rules.blue) then ign.blue = true end
+ if ports.yellow and not vports.yellow and not mesecon.is_powered(pos, rules.yellow) then ign.yellow = true end
+ if ports.green and not vports.green and not mesecon.is_powered(pos, rules.green) then ign.green = true end
+ if ports.black and not vports.black and not mesecon.is_powered(pos, rules.black) then ign.black = true end
+ if ports.white and not vports.white and not mesecon.is_powered(pos, rules.white) then ign.white = true end
+ meta:set_string("ignore_offevents", minetest.serialize(ign))
+
+ minetest.swap_node(pos, {name = new_name, param2 = node.param2})
+
+ if ports.red ~= vports.red then set_port(pos, rules.red, ports.red) end
+ if ports.blue ~= vports.blue then set_port(pos, rules.blue, ports.blue) end
+ if ports.yellow ~= vports.yellow then set_port(pos, rules.yellow, ports.yellow) end
+ if ports.green ~= vports.green then set_port(pos, rules.green, ports.green) end
+ if ports.black ~= vports.black then set_port(pos, rules.black, ports.black) end
+ if ports.white ~= vports.white then set_port(pos, rules.white, ports.white) end
+ end
+end
+
+
+-----------------
+-- Overheating --
+-----------------
+local function burn_controller(pos)
+ local node = minetest.get_node(pos)
+ node.name = BASENAME.."_burnt"
+ minetest.swap_node(pos, node)
+ minetest.get_meta(pos):set_string("lc_memory", "");
+ -- Wait for pending operations
+ minetest.after(0.2, mesecon.receptor_off, pos, mesecon.rules.flat)
+end
+
+local function overheat(pos, meta)
+ if mesecon.do_overheat(pos) then -- If too hot
+ burn_controller(pos)
+ return true
+ end
+end
+
+------------------------
+-- Ignored off events --
+------------------------
+
+local function ignore_event(event, meta)
+ if event.type ~= "off" then return false end
+ local ignore_offevents = minetest.deserialize(meta:get_string("ignore_offevents")) or {}
+ if ignore_offevents[event.pin.name] then
+ ignore_offevents[event.pin.name] = nil
+ meta:set_string("ignore_offevents", minetest.serialize(ignore_offevents))
+ return true
+ end
+end
+
+-------------------------
+-- Parsing and running --
+-------------------------
+
+local function safe_print(param)
+ print(dump(param))
+end
+
+local function safe_date()
+ return(os.date("*t",os.time()))
+end
+
+-- string.rep(str, n) with a high value for n can be used to DoS
+-- the server. Therefore, limit max. length of generated string.
+local function safe_string_rep(str, n)
+ if #str * n > mesecon.setting("luacontroller_string_rep_max", 64000) then
+ debug.sethook() -- Clear hook
+ error("string.rep: string length overflow", 2)
+ end
+
+ return string.rep(str, n)
+end
+
+-- string.find with a pattern can be used to DoS the server.
+-- Therefore, limit string.find to patternless matching.
+local function safe_string_find(...)
+ if (select(4, ...)) ~= true then
+ debug.sethook() -- Clear hook
+ error("string.find: 'plain' (fourth parameter) must always be true in a lua controlled tube")
+ end
+
+ return string.find(...)
+end
+
+local function remove_functions(x)
+ local tp = type(x)
+ if tp == "function" then
+ return nil
+ end
+
+ -- Make sure to not serialize the same table multiple times, otherwise
+ -- writing mem.test = mem in the lua controlled tube will lead to infinite recursion
+ local seen = {}
+
+ local function rfuncs(x)
+ if seen[x] then return end
+ seen[x] = true
+ if type(x) ~= "table" then return end
+
+ for key, value in pairs(x) do
+ if type(key) == "function" or type(value) == "function" then
+ x[key] = nil
+ else
+ if type(key) == "table" then
+ rfuncs(key)
+ end
+ if type(value) == "table" then
+ rfuncs(value)
+ end
+ end
+ end
+ end
+
+ rfuncs(x)
+
+ return x
+end
+
+local function get_interrupt(pos)
+ -- iid = interrupt id
+ local function interrupt(time, iid)
+ if type(time) ~= "number" then return end
+ local luac_id = minetest.get_meta(pos):get_int("luac_id")
+ mesecon.queue:add_action(pos, "pipeworks:lc_tube_interrupt", {luac_id, iid}, time, iid, 1)
+ end
+ return interrupt
+end
+
+
+local function get_digiline_send(pos)
+ if not digiline then return end
+ return function(channel, msg)
+ -- Make sure channel is string, number or boolean
+ if (type(channel) ~= "string" and type(channel) ~= "number" and type(channel) ~= "boolean") then
+ return false
+ end
+
+ -- It is technically possible to send functions over the wire since
+ -- the high performance impact of stripping those from the data has
+ -- been decided to not be worth the added realism.
+ -- Make sure serialized version of the data is not insanely long to
+ -- prevent DoS-like attacks
+ local msg_ser = minetest.serialize(msg)
+ if #msg_ser > mesecon.setting("luacontroller_digiline_maxlen", 50000) then
+ return false
+ end
+
+ minetest.after(0, function()
+ digilines.receptor_send(pos, digiline.rules.default, channel, msg)
+ end)
+ return true
+ end
+end
+
+
+local safe_globals = {
+ "assert", "error", "ipairs", "next", "pairs", "select",
+ "tonumber", "tostring", "type", "unpack", "_VERSION"
+}
+
+local function create_environment(pos, mem, event)
+ -- Gather variables for the environment
+ local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
+ local vports_copy = {}
+ for k, v in pairs(vports) do vports_copy[k] = v end
+ local rports = get_real_port_states(pos)
+
+ -- Create new library tables on each call to prevent one Luacontroller
+ -- from breaking a library and messing up other Luacontrollers.
+ local env = {
+ pin = merge_port_states(vports, rports),
+ port = vports_copy,
+ event = event,
+ mem = mem,
+ heat = mesecon.get_heat(pos),
+ heat_max = mesecon.setting("overheat_max", 20),
+ print = safe_print,
+ interrupt = get_interrupt(pos),
+ digiline_send = get_digiline_send(pos),
+ string = {
+ byte = string.byte,
+ char = string.char,
+ format = string.format,
+ len = string.len,
+ lower = string.lower,
+ upper = string.upper,
+ rep = safe_string_rep,
+ reverse = string.reverse,
+ sub = string.sub,
+ find = safe_string_find,
+ },
+ math = {
+ abs = math.abs,
+ acos = math.acos,
+ asin = math.asin,
+ atan = math.atan,
+ atan2 = math.atan2,
+ ceil = math.ceil,
+ cos = math.cos,
+ cosh = math.cosh,
+ deg = math.deg,
+ exp = math.exp,
+ floor = math.floor,
+ fmod = math.fmod,
+ frexp = math.frexp,
+ huge = math.huge,
+ ldexp = math.ldexp,
+ log = math.log,
+ log10 = math.log10,
+ max = math.max,
+ min = math.min,
+ modf = math.modf,
+ pi = math.pi,
+ pow = math.pow,
+ rad = math.rad,
+ random = math.random,
+ sin = math.sin,
+ sinh = math.sinh,
+ sqrt = math.sqrt,
+ tan = math.tan,
+ tanh = math.tanh,
+ },
+ table = {
+ concat = table.concat,
+ insert = table.insert,
+ maxn = table.maxn,
+ remove = table.remove,
+ sort = table.sort,
+ },
+ os = {
+ clock = os.clock,
+ difftime = os.difftime,
+ time = os.time,
+ datetable = safe_date,
+ },
+ }
+ env._G = env
+
+ for _, name in pairs(safe_globals) do
+ env[name] = _G[name]
+ end
+
+ return env
+end
+
+
+local function timeout()
+ debug.sethook() -- Clear hook
+ error("Code timed out!", 2)
+end
+
+
+local function create_sandbox(code, env)
+ if code:byte(1) == 27 then
+ return nil, "Binary code prohibited."
+ end
+ local f, msg = loadstring(code)
+ if not f then return nil, msg end
+ setfenv(f, env)
+
+ -- Turn off JIT optimization for user code so that count
+ -- events are generated when adding debug hooks
+ if rawget(_G, "jit") then
+ jit.off(f, true)
+ end
+
+ return function(...)
+ -- Use instruction counter to stop execution
+ -- after luacontroller_maxevents
+ local maxevents = mesecon.setting("luacontroller_maxevents", 10000)
+ debug.sethook(timeout, "", maxevents)
+ local ok, ret = pcall(f, ...)
+ debug.sethook() -- Clear hook
+ if not ok then error(ret, 0) end
+ return ret
+ end
+end
+
+
+local function load_memory(meta)
+ return minetest.deserialize(meta:get_string("lc_memory")) or {}
+end
+
+
+local function save_memory(pos, meta, mem)
+ local memstring = minetest.serialize(remove_functions(mem))
+ local memsize_max = mesecon.setting("luacontroller_memsize", 100000)
+
+ if (#memstring <= memsize_max) then
+ meta:set_string("lc_memory", memstring)
+ else
+ print("Error: lua_tube memory overflow. "..memsize_max.." bytes available, "
+ ..#memstring.." required. Controller overheats.")
+ burn_controller(pos)
+ end
+end
+
+
+local function run(pos, event)
+ local meta = minetest.get_meta(pos)
+ if overheat(pos) then return end
+ if ignore_event(event, meta) then return end
+
+ -- Load code & mem from meta
+ local mem = load_memory(meta)
+ local code = meta:get_string("code")
+
+ -- Create environment
+ local env = create_environment(pos, mem, event)
+
+ -- Create the sandbox and execute code
+ local f, msg = create_sandbox(code, env)
+ if not f then return false, msg end
+ local succ, msg = pcall(f)
+ if not succ then return false, msg end
+ if type(env.port) ~= "table" then
+ return false, "Ports set are invalid."
+ end
+
+ -- Actually set the ports
+ set_port_states(pos, env.port)
+
+ -- Save memory. This may burn the luacontroller if a memory overflow occurs.
+ save_memory(pos, meta, env.mem)
+
+ return succ, msg
+end
+
+mesecon.queue:add_function("pipeworks:lc_tube_interrupt", function (pos, luac_id, iid)
+ -- There is no lua_tube anymore / it has been reprogrammed / replaced / burnt
+ if (minetest.get_meta(pos):get_int("luac_id") ~= luac_id) then return end
+ if (minetest.registered_nodes[minetest.get_node(pos).name].is_burnt) then return end
+ run(pos, {type = "interrupt", iid = iid})
+end)
+
+local function reset_meta(pos, code, errmsg)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("code", code)
+ code = minetest.formspec_escape(code or "")
+ errmsg = minetest.formspec_escape(tostring(errmsg or ""))
+ meta:set_string("formspec", "size[12,10]"..
+ "background[-0.2,-0.25;12.4,10.75;jeija_luac_background.png]"..
+ "textarea[0.2,0.2;12.2,9.5;code;;"..code.."]"..
+ "image_button[4.75,8.75;2.5,1;jeija_luac_runbutton.png;program;]"..
+ "image_button_exit[11.72,-0.25;0.425,0.4;jeija_close_window.png;exit;]"..
+ "label[0.1,9;"..errmsg.."]")
+ meta:set_int("luac_id", math.random(1, 65535))
+end
+
+local function reset(pos)
+ set_port_states(pos, {red = false, blue = false, yellow = false,
+ green = false, black = false, white = false})
+end
+
+
+-----------------------
+-- Node Registration --
+-----------------------
+
+local output_rules = {}
+local input_rules = {}
+
+local node_box = {
+ type = "fixed",
+ fixed = {
+ pipeworks.tube_leftstub[1], -- tube segment against -X face
+ pipeworks.tube_rightstub[1], -- tube segment against +X face
+ pipeworks.tube_bottomstub[1], -- tube segment against -Y face
+ pipeworks.tube_topstub[1], -- tube segment against +Y face
+ pipeworks.tube_frontstub[1], -- tube segment against -Z face
+ pipeworks.tube_backstub[1], -- tube segment against +Z face
+ }
+}
+
+local selection_box = {
+ type = "fixed",
+ fixed = pipeworks.tube_selectboxes,
+}
+
+local digiline = {
+ receptor = {},
+ effector = {
+ action = function(pos, node, channel, msg)
+ run(pos, {type = "digiline", channel = channel, msg = msg})
+ end
+ }
+}
+local function on_receive_fields(pos, form_name, fields, sender)
+ if not fields.program then
+ return
+ end
+ local name = sender:get_player_name()
+ if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
+ minetest.record_protection_violation(pos, name)
+ return
+ end
+ reset(pos)
+ reset_meta(pos, fields.code)
+ local succ, err = run(pos, {type="program"})
+ if not succ then
+ print(err)
+ reset_meta(pos, fields.code, err)
+ end
+end
+
+local function go_back(velocity)
+ local adjlist={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=1,y=0,z=0},{x=-1,y=0,z=0}}
+ local speed = math.abs(velocity.x + velocity.y + velocity.z)
+ if speed == 0 then
+ speed = 1
+ end
+ local vel = {x = velocity.x/speed, y = velocity.y/speed, z = velocity.z/speed,speed=speed}
+ if speed >= 4.1 then
+ speed = 4
+ elseif speed >= 1.1 then
+ speed = speed - 0.1
+ else
+ speed = 1
+ end
+ vel.speed = speed
+ return pipeworks.notvel(adjlist, vel)
+end
+
+local tiles_base = {
+ "pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_3.png",
+ "pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_1.png",
+ "pipeworks_mese_tube_plain_6.png", "pipeworks_mese_tube_plain_5.png"}
+
+for red = 0, 1 do -- 0 = off 1 = on
+for blue = 0, 1 do
+for yellow = 0, 1 do
+for green = 0, 1 do
+for black = 0, 1 do
+for white = 0, 1 do
+ local cid = tostring(white)..tostring(black)..tostring(green)..
+ tostring(yellow)..tostring(blue)..tostring(red)
+ local node_name = BASENAME..cid
+ local tiles = table.copy(tiles_base)
+ if red == 1 then
+ tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_on.png^[transformR90)"
+ tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_on.png^[transformR90)"
+ tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_on.png^[transformR270)"
+ tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_on.png^[transformR90)"
+ else
+ tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_off.png^[transformR90)"
+ tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_off.png^[transformR90)"
+ tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_off.png^[transformR270)"
+ tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_off.png^[transformR90)"
+ end
+ if blue == 1 then
+ tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_on.png^[transformR270)"
+ tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_on.png^[transformR270)"
+ tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_on.png^[transformR90)"
+ tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_on.png^[transformR270)"
+ else
+ tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_off.png^[transformR270)"
+ tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_off.png^[transformR270)"
+ tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_off.png^[transformR90)"
+ tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_off.png^[transformR270)"
+ end
+ if yellow == 1 then
+ tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_on.png^[transformR180)"
+ tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_on.png^[transformR180)"
+ tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_on.png^[transformR180)"
+ tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_on.png^[transformR180)"
+ else
+ tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
+ tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
+ tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
+ tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
+ end
+ if green == 1 then
+ tiles[3] = tiles[3].."^pipeworks_lua_tube_port_on.png"
+ tiles[4] = tiles[4].."^pipeworks_lua_tube_port_on.png"
+ tiles[5] = tiles[5].."^pipeworks_lua_tube_port_on.png"
+ tiles[6] = tiles[6].."^pipeworks_lua_tube_port_on.png"
+ else
+ tiles[3] = tiles[3].."^pipeworks_lua_tube_port_off.png"
+ tiles[4] = tiles[4].."^pipeworks_lua_tube_port_off.png"
+ tiles[5] = tiles[5].."^pipeworks_lua_tube_port_off.png"
+ tiles[6] = tiles[6].."^pipeworks_lua_tube_port_off.png"
+ end
+ if black == 1 then
+ tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_on.png^[transformR180)"
+ tiles[2] = tiles[2].."^pipeworks_lua_tube_port_on.png"
+ tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_on.png^[transformR90)"
+ tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_on.png^[transformR270)"
+ else
+ tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
+ tiles[2] = tiles[2].."^pipeworks_lua_tube_port_off.png"
+ tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_off.png^[transformR90)"
+ tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_off.png^[transformR270)"
+ end
+ if white == 1 then
+ tiles[1] = tiles[1].."^pipeworks_lua_tube_port_on.png"
+ tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_on.png^[transformR180)"
+ tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_on.png^[transformR270)"
+ tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_on.png^[transformR90)"
+ else
+ tiles[1] = tiles[1].."^pipeworks_lua_tube_port_off.png"
+ tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
+ tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_off.png^[transformR270)"
+ tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_off.png^[transformR90)"
+ end
+
+ local groups = {snappy = 3, tube = 1, tubedevice = 1, overheat = 1}
+ if red + blue + yellow + green + black + white ~= 0 then
+ groups.not_in_creative_inventory = 1
+ end
+
+ output_rules[cid] = {}
+ input_rules[cid] = {}
+ if red == 1 then table.insert(output_rules[cid], rules.red) end
+ if blue == 1 then table.insert(output_rules[cid], rules.blue) end
+ if yellow == 1 then table.insert(output_rules[cid], rules.yellow) end
+ if green == 1 then table.insert(output_rules[cid], rules.green) end
+ if black == 1 then table.insert(output_rules[cid], rules.black) end
+ if white == 1 then table.insert(output_rules[cid], rules.white) end
+
+ if red == 0 then table.insert( input_rules[cid], rules.red) end
+ if blue == 0 then table.insert( input_rules[cid], rules.blue) end
+ if yellow == 0 then table.insert( input_rules[cid], rules.yellow) end
+ if green == 0 then table.insert( input_rules[cid], rules.green) end
+ if black == 0 then table.insert( input_rules[cid], rules.black) end
+ if white == 0 then table.insert( input_rules[cid], rules.white) end
+
+ local mesecons = {
+ effector = {
+ rules = input_rules[cid],
+ action_change = function (pos, _, rule_name, new_state)
+ update_real_port_states(pos, rule_name, new_state)
+ run(pos, {type=new_state, pin=rule_name})
+ end,
+ },
+ receptor = {
+ state = mesecon.state.on,
+ rules = output_rules[cid]
+ }
+ }
+
+ minetest.register_node(node_name, {
+ description = "Lua controlled Tube",
+ drawtype = "nodebox",
+ tiles = tiles,
+ paramtype = "light",
+ groups = groups,
+ drop = BASENAME.."000000",
+ sunlight_propagates = true,
+ selection_box = selection_box,
+ node_box = node_box,
+ on_construct = reset_meta,
+ on_receive_fields = on_receive_fields,
+ sounds = default.node_sound_wood_defaults(),
+ mesecons = mesecons,
+ digiline = digiline,
+ -- Virtual portstates are the ports that
+ -- the node shows as powered up (light up).
+ virtual_portstates = {
+ red = red == 1,
+ blue = blue == 1,
+ yellow = yellow == 1,
+ green = green == 1,
+ black = black == 1,
+ white = white == 1,
+ },
+ after_dig_node = function(pos, node)
+ mesecon.do_cooldown(pos)
+ mesecon.receptor_off(pos, output_rules)
+ pipeworks.after_dig(pos, node)
+ end,
+ is_luacontroller = true,
+ tubelike = 1,
+ tube = {
+ connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1},
+ priority = 50,
+ can_go = function(pos, node, velocity, stack)
+ local succ, msg = run(pos, {
+ type = "item",
+ itemstring = stack:to_string(),
+ item = stack:to_table(),
+ velocity = velocity,
+ })
+ if not succ or type(msg) ~= "string" then
+ return go_back(velocity)
+ end
+ local r = rules[msg]
+ return r and {r} or go_back(velocity)
+ end,
+ },
+ after_place_node = pipeworks.after_place,
+ on_blast = function(pos, intensity)
+ if not intensity or intensity > 1 + 3^0.5 then
+ minetest.remove_node(pos)
+ return {string.format("%s_%s", name, dropname)}
+ end
+ minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
+ pipeworks.scan_for_tube_objects(pos)
+ end,
+ on_blast = function(pos, intensity)
+ if not intensity or intensity > 1 + 3^0.5 then
+ minetest.remove_node(pos)
+ return {string.format("%s_%s", name, dropname)}
+ end
+ minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
+ pipeworks.scan_for_tube_objects(pos)
+ end,
+ })
+end
+end
+end
+end
+end
+end
+
+------------------------------------
+-- Overheated Lua controlled Tube --
+------------------------------------
+
+local tiles_burnt = table.copy(tiles_base)
+tiles_burnt[1] = tiles_burnt[1].."^(pipeworks_lua_tube_port_burnt.png^[transformR90)"
+tiles_burnt[2] = tiles_burnt[2].."^(pipeworks_lua_tube_port_burnt.png^[transformR90)"
+tiles_burnt[5] = tiles_burnt[5].."^(pipeworks_lua_tube_port_burnt.png^[transformR270)"
+tiles_burnt[6] = tiles_burnt[6].."^(pipeworks_lua_tube_port_burnt.png^[transformR90)"
+tiles_burnt[1] = tiles_burnt[1].."^(pipeworks_lua_tube_port_burnt.png^[transformR270)"
+tiles_burnt[2] = tiles_burnt[2].."^(pipeworks_lua_tube_port_burnt.png^[transformR270)"
+tiles_burnt[5] = tiles_burnt[5].."^(pipeworks_lua_tube_port_burnt.png^[transformR90)"
+tiles_burnt[6] = tiles_burnt[6].."^(pipeworks_lua_tube_port_burnt.png^[transformR270)"
+tiles_burnt[3] = tiles_burnt[3].."^(pipeworks_lua_tube_port_burnt.png^[transformR180)"
+tiles_burnt[4] = tiles_burnt[4].."^(pipeworks_lua_tube_port_burnt.png^[transformR180)"
+tiles_burnt[5] = tiles_burnt[5].."^(pipeworks_lua_tube_port_burnt.png^[transformR180)"
+tiles_burnt[6] = tiles_burnt[6].."^(pipeworks_lua_tube_port_burnt.png^[transformR180)"
+tiles_burnt[3] = tiles_burnt[3].."^pipeworks_lua_tube_port_burnt.png"
+tiles_burnt[4] = tiles_burnt[4].."^pipeworks_lua_tube_port_burnt.png"
+tiles_burnt[5] = tiles_burnt[5].."^pipeworks_lua_tube_port_burnt.png"
+tiles_burnt[6] = tiles_burnt[6].."^pipeworks_lua_tube_port_burnt.png"
+tiles_burnt[1] = tiles_burnt[1].."^(pipeworks_lua_tube_port_burnt.png^[transformR180)"
+tiles_burnt[2] = tiles_burnt[2].."^pipeworks_lua_tube_port_burnt.png"
+tiles_burnt[3] = tiles_burnt[3].."^(pipeworks_lua_tube_port_burnt.png^[transformR90)"
+tiles_burnt[4] = tiles_burnt[4].."^(pipeworks_lua_tube_port_burnt.png^[transformR270)"
+tiles_burnt[1] = tiles_burnt[1].."^pipeworks_lua_tube_port_burnt.png"
+tiles_burnt[2] = tiles_burnt[2].."^(pipeworks_lua_tube_port_burnt.png^[transformR180)"
+tiles_burnt[3] = tiles_burnt[3].."^(pipeworks_lua_tube_port_burnt.png^[transformR270)"
+tiles_burnt[4] = tiles_burnt[4].."^(pipeworks_lua_tube_port_burnt.png^[transformR90)"
+
+minetest.register_node(BASENAME .. "_burnt", {
+ drawtype = "nodebox",
+ tiles = tiles_burnt,
+ is_burnt = true,
+ paramtype = "light",
+ groups = {snappy = 3, tube = 1, tubedevice = 1, not_in_creative_inventory=1},
+ drop = BASENAME.."000000",
+ sunlight_propagates = true,
+ selection_box = selection_box,
+ node_box = node_box,
+ on_construct = reset_meta,
+ on_receive_fields = on_receive_fields,
+ sounds = default.node_sound_wood_defaults(),
+ virtual_portstates = {red = false, blue = false, yellow = false,
+ green = false, black = false, white = false},
+ mesecons = {
+ effector = {
+ rules = mesecon.rules.alldirs,
+ action_change = function(pos, _, rule_name, new_state)
+ update_real_port_states(pos, rule_name, new_state)
+ end,
+ },
+ },
+ tubelike = 1,
+ tube = {
+ connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1},
+ priority = 50,
+ },
+ after_place_node = pipeworks.after_place,
+ after_dig_node = pipeworks.after_dig,
+ on_blast = function(pos, intensity)
+ if not intensity or intensity > 1 + 3^0.5 then
+ minetest.remove_node(pos)
+ return {string.format("%s_%s", name, dropname)}
+ end
+ minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
+ pipeworks.scan_for_tube_objects(pos)
+ end,
+})
+
+------------------------
+-- Craft Registration --
+------------------------
+
+minetest.register_craft({
+ type = "shapeless",
+ output = BASENAME.."000000",
+ recipe = {"pipeworks:mese_tube_000000", "mesecons_luacontroller:luacontroller0000"},
+})
diff --git a/pipeworks/models.lua b/pipeworks/models.lua
index 3be773c..d9928d2 100644
--- a/pipeworks/models.lua
+++ b/pipeworks/models.lua
@@ -33,8 +33,8 @@ pipeworks.tube_frontstub = {
}
pipeworks.tube_backstub = {
- { -9/64, -9/64, -9/64, 9/64, 9/64, 32/64 }, -- tube segment against -Z face
-}
+ { -9/64, -9/64, -9/64, 9/64, 9/64, 32/64 }, -- tube segment against +Z face
+}
pipeworks.tube_boxes = {pipeworks.tube_leftstub, pipeworks.tube_rightstub, pipeworks.tube_bottomstub, pipeworks.tube_topstub, pipeworks.tube_frontstub, pipeworks.tube_backstub}
diff --git a/pipeworks/settingtypes.txt b/pipeworks/settingtypes.txt
index 1d3c10c..cd6efbc 100644
--- a/pipeworks/settingtypes.txt
+++ b/pipeworks/settingtypes.txt
@@ -34,6 +34,9 @@ pipeworks_enable_digiline_detector_tube (Enable Digiline Detector Tube) bool tru
#Enable mesecon signal conducting tube.
pipeworks_enable_conductor_tube (Enable Conductor Tube) bool true
+#Enable digiline signal conducting tube.
+pipeworks_enable_digiline_conductor_tube (Enable Digiline Conductor Tube) bool true
+
#Enable accelerator tube.
pipeworks_enable_accelerator_tube (Enable Accelerator Tube) bool true
@@ -60,6 +63,10 @@ pipeworks_enable_one_way_tube (Enable One Way Tube) bool true
#always go to it if there are multible ways.
pipeworks_enable_priority_tube (Enable High Priority Tube) bool true
+#Enable lua controlled tube.
+#It is comparable with mesecons luacontroller.
+pipeworks_enable_lua_tube (Enable Lua controlled Tube) bool true
+
#Enable cyclic mode.
pipeworks_enable_cyclic_mode (Enable Cyclic Mode) bool true
@@ -67,4 +74,4 @@ pipeworks_enable_cyclic_mode (Enable Cyclic Mode) bool true
pipeworks_drop_on_routing_fail (Drop On Routing Fail) bool false
#Delete item on clearobject.
-pipeworks_delete_item_on_clearobject (Delete Item On Clearobject) bool true \ No newline at end of file
+pipeworks_delete_item_on_clearobject (Delete Item On Clearobject) bool true
diff --git a/pipeworks/signal_tubes.lua b/pipeworks/signal_tubes.lua
index a0a8039..b955a16 100644
--- a/pipeworks/signal_tubes.lua
+++ b/pipeworks/signal_tubes.lua
@@ -67,7 +67,8 @@ if pipeworks.enable_detector_tube then
})
end
-if minetest.get_modpath("digilines") and pipeworks.enable_digiline_detector_tube then
+local digiline_enabled = minetest.get_modpath("digilines") ~= nil
+if digiline_enabled and pipeworks.enable_digiline_detector_tube then
pipeworks.register_tube("pipeworks:digiline_detector_tube", {
description = "Digiline Detecting Pneumatic Tube Segment",
inventory_image = "pipeworks_digiline_detector_tube_inv.png",
@@ -147,14 +148,80 @@ if pipeworks.enable_conductor_tube then
},
})
- minetest.register_craft( {
- output = "pipeworks:conductor_tube_off_1 6",
- recipe = {
- { "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
- { "mesecons:mesecon", "mesecons:mesecon", "mesecons:mesecon" },
- { "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
- },
+ minetest.register_craft({
+ type = "shapeless",
+ output = "pipeworks:conductor_tube_off_1",
+ recipe = {"pipeworks:tube_1", "mesecons:mesecon"}
})
end
+if digiline_enabled and pipeworks.enable_digiline_conductor_tube then
+ pipeworks.register_tube("pipeworks:digiline_conductor_tube", {
+ description = "Digiline Conducting Pneumatic Tube Segment",
+ inventory_image = "pipeworks_tube_inv.png^pipeworks_digiline_conductor_tube_inv.png",
+ short = "pipeworks_tube_short.png^pipeworks_digiline_conductor_tube_short.png",
+ plain = {"pipeworks_tube_plain.png^pipeworks_digiline_conductor_tube_plain.png"},
+ noctr = {"pipeworks_tube_noctr.png^pipeworks_digiline_conductor_tube_noctr.png"},
+ ends = {"pipeworks_tube_end.png^pipeworks_digiline_conductor_tube_end.png"},
+ node_def = {digiline = {wire = {rules = pipeworks.digilines_rules}}},
+ })
+ minetest.register_craft({
+ type = "shapeless",
+ output = "pipeworks:digiline_conductor_tube_1",
+ recipe = {"pipeworks:tube_1", "digilines:wire_std_00000000"}
+ })
+end
+if digiline_enabled and pipeworks.enable_digiline_conductor_tube and
+ pipeworks.enable_conductor_tube then
+ pipeworks.register_tube("pipeworks:mesecon_and_digiline_conductor_tube_off", {
+ description = "Mesecon and Digiline Conducting Pneumatic Tube Segment",
+ inventory_image = "pipeworks_conductor_tube_inv.png^pipeworks_digiline_conductor_tube_inv.png",
+ short = "pipeworks_conductor_tube_short.png^pipeworks_digiline_conductor_tube_short.png",
+ plain = {"pipeworks_conductor_tube_plain.png^pipeworks_digiline_conductor_tube_plain.png"},
+ noctr = {"pipeworks_conductor_tube_noctr.png^pipeworks_digiline_conductor_tube_noctr.png"},
+ ends = {"pipeworks_conductor_tube_end.png^pipeworks_digiline_conductor_tube_end.png"},
+ node_def = {
+ digiline = {wire = {rules = pipeworks.digilines_rules}},
+ groups = {mesecon = 2},
+ mesecons = {conductor = {
+ state = "off",
+ rules = pipeworks.mesecons_rules,
+ onstate = "pipeworks:mesecon_and_digiline_conductor_tube_on_#id"
+ }},
+ },
+ })
+ pipeworks.register_tube("pipeworks:mesecon_and_digiline_conductor_tube_on", {
+ description = "Mesecon and Digiline Conducting Pneumatic Tube Segment on (you hacker you)",
+ inventory_image = "pipeworks_conductor_tube_inv.png^pipeworks_digiline_conductor_tube_inv.png",
+ short = "pipeworks_conductor_tube_short.png^pipeworks_digiline_conductor_tube_short.png",
+ plain = {"pipeworks_conductor_tube_on_plain.png^pipeworks_digiline_conductor_tube_plain.png"},
+ noctr = {"pipeworks_conductor_tube_on_noctr.png^pipeworks_digiline_conductor_tube_noctr.png"},
+ ends = {"pipeworks_conductor_tube_on_end.png^pipeworks_digiline_conductor_tube_end.png"},
+ node_def = {
+ digiline = {wire = {rules = pipeworks.digilines_rules}},
+ groups = {mesecon = 2, not_in_creative_inventory = 1},
+ drop = "pipeworks:mesecon_and_digiline_conductor_tube_off_1",
+ mesecons = {conductor = {
+ state = "on",
+ rules = pipeworks.mesecons_rules,
+ offstate = "pipeworks:mesecon_and_digiline_conductor_tube_off_#id"}
+ },
+ },
+ })
+ minetest.register_craft({
+ type = "shapeless",
+ output = "pipeworks:mesecon_and_digiline_conductor_tube_off_1",
+ recipe = {"pipeworks:tube_1", "mesecons:mesecon", "digilines:wire_std_00000000"}
+ })
+ minetest.register_craft({
+ type = "shapeless",
+ output = "pipeworks:mesecon_and_digiline_conductor_tube_off_1",
+ recipe = {"pipeworks:conductor_tube_off_1", "digilines:wire_std_00000000"}
+ })
+ minetest.register_craft({
+ type = "shapeless",
+ output = "pipeworks:mesecon_and_digiline_conductor_tube_off_1",
+ recipe = {"pipeworks:digiline_conductor_tube_1", "mesecons:mesecon"}
+ })
+end
diff --git a/pipeworks/textures/pipeworks_digiline_conductor_tube_end.png b/pipeworks/textures/pipeworks_digiline_conductor_tube_end.png
new file mode 100644
index 0000000..e6c2cfc
--- /dev/null
+++ b/pipeworks/textures/pipeworks_digiline_conductor_tube_end.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_digiline_conductor_tube_inv.png b/pipeworks/textures/pipeworks_digiline_conductor_tube_inv.png
new file mode 100644
index 0000000..7f23c8c
--- /dev/null
+++ b/pipeworks/textures/pipeworks_digiline_conductor_tube_inv.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_digiline_conductor_tube_noctr.png b/pipeworks/textures/pipeworks_digiline_conductor_tube_noctr.png
new file mode 100644
index 0000000..b58a4d3
--- /dev/null
+++ b/pipeworks/textures/pipeworks_digiline_conductor_tube_noctr.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_digiline_conductor_tube_plain.png b/pipeworks/textures/pipeworks_digiline_conductor_tube_plain.png
new file mode 100644
index 0000000..de31307
--- /dev/null
+++ b/pipeworks/textures/pipeworks_digiline_conductor_tube_plain.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_digiline_conductor_tube_short.png b/pipeworks/textures/pipeworks_digiline_conductor_tube_short.png
new file mode 100644
index 0000000..6108485
--- /dev/null
+++ b/pipeworks/textures/pipeworks_digiline_conductor_tube_short.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_lua_tube_port_burnt.png b/pipeworks/textures/pipeworks_lua_tube_port_burnt.png
new file mode 100644
index 0000000..3384eff
--- /dev/null
+++ b/pipeworks/textures/pipeworks_lua_tube_port_burnt.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_lua_tube_port_off.png b/pipeworks/textures/pipeworks_lua_tube_port_off.png
new file mode 100644
index 0000000..03f7069
--- /dev/null
+++ b/pipeworks/textures/pipeworks_lua_tube_port_off.png
Binary files differ
diff --git a/pipeworks/textures/pipeworks_lua_tube_port_on.png b/pipeworks/textures/pipeworks_lua_tube_port_on.png
new file mode 100644
index 0000000..a7e3d09
--- /dev/null
+++ b/pipeworks/textures/pipeworks_lua_tube_port_on.png
Binary files differ