update some more mods
|
@ -0,0 +1,17 @@
|
|||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
----------
|
||||
|
||||
This license is commonly known as "WTFPL".
|
|
@ -1,5 +1,7 @@
|
|||
This simple mod uses nodeboxes to supply a complete set of 3D flanged pipes,
|
||||
along with "valve" and "pump" devices.
|
||||
This mod uses nodeboxes to supply a complete set of 3D pipes and tubes,
|
||||
along devices that work with them.
|
||||
|
||||
See http://vanessae.github.io/pipeworks/ for detailed information about usage of this mod.
|
||||
|
||||
Unlike the previous version of this mod, these pipes are rounded, and when
|
||||
placed, they'll automatically join together as needed. Pipes can go vertically
|
||||
|
@ -14,21 +16,7 @@ windows, as if full (the two colors should also be easy to select if you want
|
|||
to change them in a paint program). These windows only appear on straight
|
||||
lengths and on certain junctions.
|
||||
|
||||
There are no crafting recipes, yet, but you can use /giveme as usual, namely
|
||||
"/giveme pipeworks:pipe 999" or so, and then place them as needed. See
|
||||
init.lua for more details.
|
||||
|
||||
This mod is intended to be used as a basis or at least as sort of a model for
|
||||
something else to build on (perhaps a nicer-looking oil mod?), and does not
|
||||
provide any of the code necessary to cause anything to flow through them. Like
|
||||
the pipes, the valve and pump don't do anything useful yet, but you can punch
|
||||
them to turn them "on" and "off". Note that the valve and pump textures and
|
||||
shapes are not yet complete (hence their boxy appearance).
|
||||
|
||||
This mod is a work in progress.
|
||||
|
||||
Please note that owing to the nature of this mod, I have opted to use 64px
|
||||
textures. Anything less just looks terrible.
|
||||
|
||||
If you don't need the old node names from the previous version of this mod,
|
||||
edit init.lua and comment-out the 'dofile' line at the top.
|
||||
|
|
|
@ -1,59 +1,101 @@
|
|||
local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second
|
||||
|
||||
local function make_inventory_cache(invlist)
|
||||
local l = {}
|
||||
for _, stack in ipairs(invlist) do
|
||||
l[stack:get_name()] = (l[stack:get_name()] or 0) + stack:get_count()
|
||||
end
|
||||
return l
|
||||
end
|
||||
|
||||
function autocraft(inventory)
|
||||
local recipe=inventory:get_list("recipe")
|
||||
local function autocraft(inventory, pos)
|
||||
local recipe = inventory:get_list("recipe")
|
||||
local recipe_last
|
||||
local result
|
||||
local new
|
||||
for i=1,9 do
|
||||
recipe[i]=ItemStack({name=recipe[i]:get_name(),count=1})
|
||||
|
||||
if autocrafterCache[minetest.hash_node_position(pos)] == nil then
|
||||
recipe_last = {}
|
||||
for i = 1, 9 do
|
||||
recipe_last[i] = recipe[i]
|
||||
recipe[i] = ItemStack({name = recipe[i]:get_name(), count = 1})
|
||||
end
|
||||
result, new = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
|
||||
autocrafterCache[minetest.hash_node_position(pos)] = {["recipe"] = recipe, ["result"] = result, ["new"] = new}
|
||||
else
|
||||
local autocrafterCacheEntry = autocrafterCache[minetest.hash_node_position(pos)]
|
||||
recipe_last = autocrafterCacheEntry["recipe"]
|
||||
result = autocrafterCacheEntry["result"]
|
||||
new = autocrafterCacheEntry["new"]
|
||||
local recipeUnchanged = true
|
||||
for i = 1, 9 do
|
||||
if recipe[i]:get_name() ~= recipe_last[i]:get_name() then
|
||||
recipeUnchanged = false
|
||||
break
|
||||
end
|
||||
if recipe[i]:get_count() ~= recipe_last[i]:get_count() then
|
||||
recipeUnchanged = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if recipeUnchanged then
|
||||
else
|
||||
for i = 1, 9 do
|
||||
recipe_last[i] = recipe[i]
|
||||
recipe[i] = ItemStack({name = recipe[i]:get_name(), count = 1})
|
||||
end
|
||||
result, new = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
|
||||
autocrafterCache[minetest.hash_node_position(pos)] = {["recipe"] = recipe, ["result"] = result, ["new"] = new}
|
||||
end
|
||||
end
|
||||
result,new=minetest.get_craft_result({method="normal",width=3,items=recipe})
|
||||
local input=inventory:get_list("input")
|
||||
|
||||
if result.item:is_empty() then return end
|
||||
result=result.item
|
||||
local to_use={}
|
||||
for _,item in ipairs(recipe) do
|
||||
if item~=nil and not item:is_empty() then
|
||||
if to_use[item:get_name()]==nil then
|
||||
to_use[item:get_name()]=1
|
||||
result = result.item
|
||||
if not inventory:room_for_item("dst", result) then return end
|
||||
local to_use = {}
|
||||
for _, item in ipairs(recipe) do
|
||||
if item~= nil and not item:is_empty() then
|
||||
if to_use[item:get_name()] == nil then
|
||||
to_use[item:get_name()] = 1
|
||||
else
|
||||
to_use[item:get_name()]=to_use[item:get_name()]+1
|
||||
to_use[item:get_name()] = to_use[item:get_name()]+1
|
||||
end
|
||||
end
|
||||
end
|
||||
local stack
|
||||
for itemname,number in pairs(to_use) do
|
||||
stack=ItemStack({name=itemname, count=number})
|
||||
if not inventory:contains_item("src",stack) then return end
|
||||
local invcache = make_inventory_cache(inventory:get_list("src"))
|
||||
for itemname, number in pairs(to_use) do
|
||||
if (not invcache[itemname]) or invcache[itemname] < number then return end
|
||||
end
|
||||
for itemname,number in pairs(to_use) do
|
||||
stack=ItemStack({name=itemname, count=number})
|
||||
inventory:remove_item("src",stack)
|
||||
for itemname, number in pairs(to_use) do
|
||||
for i = 1, number do -- We have to do that since remove_item does not work if count > stack_max
|
||||
inventory:remove_item("src", ItemStack(itemname))
|
||||
end
|
||||
end
|
||||
inventory:add_item("dst",result)
|
||||
for i=1,9 do
|
||||
inventory:add_item("dst",new.items[i])
|
||||
inventory:add_item("dst", result)
|
||||
for i = 1, 9 do
|
||||
inventory:add_item("dst", new.items[i])
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("pipeworks:autocrafter",{
|
||||
description = "Autocrafter",
|
||||
drawtype="normal",
|
||||
tiles={"pipeworks_autocrafter.png"},
|
||||
groups={snappy=3,tubedevice=1,tubedevice_receiver=1},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:add_item("src",stack)
|
||||
end,
|
||||
can_insert=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:room_for_item("src",stack)
|
||||
end,
|
||||
input_inventory="dst"},
|
||||
minetest.register_node("pipeworks:autocrafter", {
|
||||
description = "Autocrafter",
|
||||
drawtype = "normal",
|
||||
tiles = {"pipeworks_autocrafter.png"},
|
||||
groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1},
|
||||
tube = {insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:add_item("src", stack)
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:room_for_item("src", stack)
|
||||
end,
|
||||
input_inventory = "dst",
|
||||
connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"size[8,11]"..
|
||||
"list[current_name;recipe;0,0;3,3;]"..
|
||||
|
@ -62,19 +104,28 @@ minetest.register_node("pipeworks:autocrafter",{
|
|||
"list[current_player;main;0,7;8,4;]")
|
||||
meta:set_string("infotext", "Autocrafter")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("src",3*8)
|
||||
inv:set_size("recipe",3*3)
|
||||
inv:set_size("dst",4*3)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
inv:set_size("src", 3*8)
|
||||
inv:set_size("recipe", 3*3)
|
||||
inv:set_size("dst", 4*3)
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return (inv:is_empty("src") and inv:is_empty("recipe") and inv:is_empty("dst"))
|
||||
end})
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
autocrafterCache[minetest.hash_node_position(pos)] = nil
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({nodenames={"pipeworks:autocrafter"},interval=1,chance=1,
|
||||
action=function(pos,node)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
autocraft(inv)
|
||||
end})
|
||||
minetest.register_abm({nodenames = {"pipeworks:autocrafter"}, interval = 1, chance = 1,
|
||||
action = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
autocraft(inv, pos)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,234 +0,0 @@
|
|||
-- autorouting for pipes
|
||||
|
||||
function pipe_scanforobjects(pos)
|
||||
pipe_autoroute({ x=pos.x-1, y=pos.y , z=pos.z }, "_loaded")
|
||||
pipe_autoroute({ x=pos.x+1, y=pos.y , z=pos.z }, "_loaded")
|
||||
pipe_autoroute({ x=pos.x , y=pos.y-1, z=pos.z }, "_loaded")
|
||||
pipe_autoroute({ x=pos.x , y=pos.y+1, z=pos.z }, "_loaded")
|
||||
pipe_autoroute({ x=pos.x , y=pos.y , z=pos.z-1 }, "_loaded")
|
||||
pipe_autoroute({ x=pos.x , y=pos.y , z=pos.z+1 }, "_loaded")
|
||||
pipe_autoroute(pos, "_loaded")
|
||||
|
||||
pipe_autoroute({ x=pos.x-1, y=pos.y , z=pos.z }, "_empty")
|
||||
pipe_autoroute({ x=pos.x+1, y=pos.y , z=pos.z }, "_empty")
|
||||
pipe_autoroute({ x=pos.x , y=pos.y-1, z=pos.z }, "_empty")
|
||||
pipe_autoroute({ x=pos.x , y=pos.y+1, z=pos.z }, "_empty")
|
||||
pipe_autoroute({ x=pos.x , y=pos.y , z=pos.z-1 }, "_empty")
|
||||
pipe_autoroute({ x=pos.x , y=pos.y , z=pos.z+1 }, "_empty")
|
||||
pipe_autoroute(pos, "_empty")
|
||||
end
|
||||
|
||||
function pipe_autoroute(pos, state)
|
||||
nctr = minetest.env:get_node(pos)
|
||||
if (string.find(nctr.name, "pipeworks:pipe_") == nil) then return end
|
||||
|
||||
pipes_scansurroundings(pos)
|
||||
|
||||
nsurround = pxm..pxp..pym..pyp..pzm..pzp
|
||||
if nsurround == "000000" then nsurround = "110000" end
|
||||
minetest.env:add_node(pos, { name = "pipeworks:pipe_"..nsurround..state })
|
||||
end
|
||||
|
||||
-- autorouting for pneumatic tubes
|
||||
|
||||
function tube_scanforobjects(pos)
|
||||
tube_autoroute({ x=pos.x-1, y=pos.y , z=pos.z })
|
||||
tube_autoroute({ x=pos.x+1, y=pos.y , z=pos.z })
|
||||
tube_autoroute({ x=pos.x , y=pos.y-1, z=pos.z })
|
||||
tube_autoroute({ x=pos.x , y=pos.y+1, z=pos.z })
|
||||
tube_autoroute({ x=pos.x , y=pos.y , z=pos.z-1 })
|
||||
tube_autoroute({ x=pos.x , y=pos.y , z=pos.z+1 })
|
||||
tube_autoroute(pos)
|
||||
end
|
||||
|
||||
function in_table(table,element)
|
||||
for _,el in ipairs(table) do
|
||||
if el==element then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function is_tube(nodename)
|
||||
return in_table(tubenodes,nodename)
|
||||
end
|
||||
|
||||
function tube_autoroute(pos)
|
||||
nctr = minetest.env:get_node(pos)
|
||||
--print ("minetest.get_item_group("..nctr.name..',"tubedevice") == '..minetest.get_item_group(nctr.name, "tubedevice"))
|
||||
if (is_tube(nctr.name) == nil)
|
||||
and minetest.get_item_group(nctr.name, "tubedevice") ~= 1 then return end
|
||||
|
||||
pxm=0
|
||||
pxp=0
|
||||
pym=0
|
||||
pyp=0
|
||||
pzm=0
|
||||
pzp=0
|
||||
|
||||
nxm = minetest.env:get_node({ x=pos.x-1, y=pos.y , z=pos.z })
|
||||
nxp = minetest.env:get_node({ x=pos.x+1, y=pos.y , z=pos.z })
|
||||
nym = minetest.env:get_node({ x=pos.x , y=pos.y-1, z=pos.z })
|
||||
nyp = minetest.env:get_node({ x=pos.x , y=pos.y+1, z=pos.z })
|
||||
nzm = minetest.env:get_node({ x=pos.x , y=pos.y , z=pos.z-1 })
|
||||
nzp = minetest.env:get_node({ x=pos.x , y=pos.y , z=pos.z+1 })
|
||||
|
||||
if is_tube(nxm.name)
|
||||
or minetest.get_item_group(nxm.name, "tubedevice") == 1 then pxm=1 end
|
||||
if is_tube(nxp.name)
|
||||
or minetest.get_item_group(nxp.name, "tubedevice") == 1 then pxp=1 end
|
||||
if is_tube(nym.name)
|
||||
or minetest.get_item_group(nym.name, "tubedevice") == 1 then pym=1 end
|
||||
if is_tube(nyp.name)
|
||||
or minetest.get_item_group(nyp.name, "tubedevice") == 1 then pyp=1 end
|
||||
if is_tube(nzm.name)
|
||||
or minetest.get_item_group(nzm.name, "tubedevice") == 1 then pzm=1 end
|
||||
if is_tube(nzp.name)
|
||||
or minetest.get_item_group(nzp.name, "tubedevice") == 1 then pzp=1 end
|
||||
|
||||
nsurround = pxm..pxp..pym..pyp..pzm..pzp
|
||||
if is_tube(nctr.name) then
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local meta0=meta:to_table()
|
||||
nctr.name=string.sub(nctr.name,1,-7)..nsurround
|
||||
minetest.env:add_node(pos, nctr)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
meta:from_table(meta0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- auto-rotation code for various devices the tubes attach to
|
||||
|
||||
function pipes_scansurroundings(pos)
|
||||
pxm=0
|
||||
pxp=0
|
||||
pym=0
|
||||
pyp=0
|
||||
pzm=0
|
||||
pzp=0
|
||||
|
||||
nxm = minetest.env:get_node({ x=pos.x-1, y=pos.y , z=pos.z })
|
||||
nxp = minetest.env:get_node({ x=pos.x+1, y=pos.y , z=pos.z })
|
||||
nym = minetest.env:get_node({ x=pos.x , y=pos.y-1, z=pos.z })
|
||||
nyp = minetest.env:get_node({ x=pos.x , y=pos.y+1, z=pos.z })
|
||||
nzm = minetest.env:get_node({ x=pos.x , y=pos.y , z=pos.z-1 })
|
||||
nzp = minetest.env:get_node({ x=pos.x , y=pos.y , z=pos.z+1 })
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:pipe_") ~= nil) then pxm=1 end
|
||||
if (string.find(nxp.name, "pipeworks:pipe_") ~= nil) then pxp=1 end
|
||||
if (string.find(nym.name, "pipeworks:pipe_") ~= nil) then pym=1 end
|
||||
if (string.find(nyp.name, "pipeworks:pipe_") ~= nil) then pyp=1 end
|
||||
if (string.find(nzm.name, "pipeworks:pipe_") ~= nil) then pzm=1 end
|
||||
if (string.find(nzp.name, "pipeworks:pipe_") ~= nil) then pzp=1 end
|
||||
|
||||
-- Special handling for valves...
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:valve") ~= nil)
|
||||
and (nxm.param2 == 0 or nxm.param2 == 2) then
|
||||
pxm=1
|
||||
end
|
||||
|
||||
if (string.find(nxp.name, "pipeworks:valve") ~= nil)
|
||||
and (nxp.param2 == 0 or nxp.param2 == 2) then
|
||||
pxp=1
|
||||
end
|
||||
|
||||
if (string.find(nzm.name, "pipeworks:valve") ~= nil)
|
||||
and (nzm.param2 == 1 or nzm.param2 == 3) then
|
||||
pzm=1
|
||||
end
|
||||
|
||||
if (string.find(nzp.name, "pipeworks:valve") ~= nil)
|
||||
and (nzp.param2 == 1 or nzp.param2 == 3) then
|
||||
pzp=1
|
||||
end
|
||||
|
||||
-- ...spigots...
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:spigot") ~= nil)
|
||||
and nxm.param2 == 1 then
|
||||
pxm=1
|
||||
end
|
||||
|
||||
if (string.find(nxp.name, "pipeworks:spigot") ~= nil)
|
||||
and nxp.param2 == 3 then
|
||||
pxp=1
|
||||
end
|
||||
|
||||
if (string.find(nzm.name, "pipeworks:spigot") ~= nil)
|
||||
and nzm.param2 == 0 then
|
||||
pzm=1
|
||||
end
|
||||
|
||||
if (string.find(nzp.name, "pipeworks:spigot") ~= nil)
|
||||
and nzp.param2 == 2 then
|
||||
pzp=1
|
||||
end
|
||||
|
||||
-- ...sealed pipe entry/exit...
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:entry_panel") ~= nil)
|
||||
and (nxm.param2 == 1 or nxm.param2 == 3) then
|
||||
pxm=1
|
||||
end
|
||||
|
||||
if (string.find(nxp.name, "pipeworks:entry_panel") ~= nil)
|
||||
and (nxp.param2 == 1 or nxp.param2 == 3) then
|
||||
pxp=1
|
||||
end
|
||||
|
||||
if (string.find(nzm.name, "pipeworks:entry_panel") ~= nil)
|
||||
and (nzm.param2 == 0 or nzm.param2 == 2) then
|
||||
pzm=1
|
||||
end
|
||||
|
||||
if (string.find(nzp.name, "pipeworks:entry_panel") ~= nil)
|
||||
and (nzp.param2 == 0 or nzp.param2 == 2) then
|
||||
pzp=1
|
||||
end
|
||||
|
||||
-- ...pumps, grates...
|
||||
|
||||
if (string.find(nym.name, "pipeworks:grating") ~= nil) or
|
||||
(string.find(nym.name, "pipeworks:pump") ~= nil) then
|
||||
pym=1
|
||||
end
|
||||
|
||||
-- ... and storage tanks.
|
||||
|
||||
if (string.find(nym.name, "pipeworks:storage_tank_") ~= nil) then
|
||||
pym=1
|
||||
end
|
||||
|
||||
if (string.find(nyp.name, "pipeworks:storage_tank_") ~= nil) then
|
||||
pyp=1
|
||||
end
|
||||
|
||||
-- ...extra devices specified via the function's parameters
|
||||
-- ...except that this part is not implemented yet
|
||||
--
|
||||
-- xxx = nxm, nxp, nym, nyp, nzm, or nzp depending on the direction to check
|
||||
-- yyy = pxm, pxp, pym, pyp, pzm, or pzp accordingly.
|
||||
--
|
||||
-- if string.find(xxx.name, "modname:nodename") ~= nil then
|
||||
-- yyy = 1
|
||||
-- end
|
||||
--
|
||||
-- for example:
|
||||
--
|
||||
-- if string.find(nym.name, "aero:outlet") ~= nil then
|
||||
-- pym = 1
|
||||
-- end
|
||||
--
|
||||
|
||||
end
|
||||
|
||||
function pipe_look_for_stackable_tanks(pos)
|
||||
local tym = minetest.env:get_node({ x=pos.x , y=pos.y-1, z=pos.z })
|
||||
|
||||
if string.find(tym.name, "pipeworks:storage_tank_") ~= nil or
|
||||
string.find(tym.name, "pipeworks:expansion_tank_") ~= nil then
|
||||
minetest.env:add_node(pos, { name = "pipeworks:expansion_tank_0", param2 = tym.param2})
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
-- autorouting for pipes
|
||||
local tube_table = {[0] = 1, 2, 2, 4, 2, 4, 4, 5, 2, 3, 4, 6, 4, 6, 5, 7, 2, 4, 3, 6, 4, 5, 6, 7, 4, 6, 6, 8, 5, 7, 7, 9, 2, 4, 4, 5, 3, 6, 6, 7, 4, 6, 5, 7, 6, 8, 7, 9, 4, 5, 6, 7, 6, 7, 8, 9, 5, 7, 7, 9, 7, 9, 9, 10}
|
||||
local tube_table_facedirs = {[0] = 0, 0, 5, 0, 3, 4, 3, 0, 2, 0, 2, 0, 6, 4, 3, 0, 7, 12, 5, 12, 7, 4, 5, 5, 18, 20, 16, 0, 7, 4, 7, 0, 1, 8, 1, 1, 1, 13, 1, 1, 10, 8, 2, 2, 17, 4, 3, 6, 9, 9, 9, 9, 21, 13, 1, 1, 10, 10, 11, 2, 19, 4, 3, 0}
|
||||
local function autoroute_pipes(pos)
|
||||
local nctr = minetest.get_node(pos)
|
||||
local state = "_empty"
|
||||
if (string.find(nctr.name, "pipeworks:pipe_") == nil) then return end
|
||||
if (string.find(nctr.name, "_loaded") ~= nil) then state = "_loaded" end
|
||||
local nsurround = pipeworks.scan_pipe_surroundings(pos)
|
||||
|
||||
if nsurround == 0 then nsurround = 9 end
|
||||
minetest.add_node(pos, {name = "pipeworks:pipe_"..tube_table[nsurround]..state,
|
||||
param2 = tube_table_facedirs[nsurround]})
|
||||
end
|
||||
|
||||
function pipeworks.scan_for_pipe_objects(pos)
|
||||
autoroute_pipes({ x=pos.x-1, y=pos.y , z=pos.z })
|
||||
autoroute_pipes({ x=pos.x+1, y=pos.y , z=pos.z })
|
||||
autoroute_pipes({ x=pos.x , y=pos.y-1, z=pos.z })
|
||||
autoroute_pipes({ x=pos.x , y=pos.y+1, z=pos.z })
|
||||
autoroute_pipes({ x=pos.x , y=pos.y , z=pos.z-1 })
|
||||
autoroute_pipes({ x=pos.x , y=pos.y , z=pos.z+1 })
|
||||
autoroute_pipes(pos)
|
||||
end
|
||||
|
||||
-- auto-rotation code for various devices the tubes attach to
|
||||
|
||||
function pipeworks.scan_pipe_surroundings(pos)
|
||||
local pxm=0
|
||||
local pxp=0
|
||||
local pym=0
|
||||
local pyp=0
|
||||
local pzm=0
|
||||
local pzp=0
|
||||
|
||||
local nxm = minetest.get_node({ x=pos.x-1, y=pos.y , z=pos.z })
|
||||
local nxp = minetest.get_node({ x=pos.x+1, y=pos.y , z=pos.z })
|
||||
local nym = minetest.get_node({ x=pos.x , y=pos.y-1, z=pos.z })
|
||||
local nyp = minetest.get_node({ x=pos.x , y=pos.y+1, z=pos.z })
|
||||
local nzm = minetest.get_node({ x=pos.x , y=pos.y , z=pos.z-1 })
|
||||
local nzp = minetest.get_node({ x=pos.x , y=pos.y , z=pos.z+1 })
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:pipe_") ~= nil) then pxm=1 end
|
||||
if (string.find(nxp.name, "pipeworks:pipe_") ~= nil) then pxp=1 end
|
||||
if (string.find(nym.name, "pipeworks:pipe_") ~= nil) then pym=1 end
|
||||
if (string.find(nyp.name, "pipeworks:pipe_") ~= nil) then pyp=1 end
|
||||
if (string.find(nzm.name, "pipeworks:pipe_") ~= nil) then pzm=1 end
|
||||
if (string.find(nzp.name, "pipeworks:pipe_") ~= nil) then pzp=1 end
|
||||
|
||||
-- Special handling for valves...
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:valve") ~= nil)
|
||||
and (nxm.param2 == 0 or nxm.param2 == 2) then
|
||||
pxm=1
|
||||
end
|
||||
|
||||
if (string.find(nxp.name, "pipeworks:valve") ~= nil)
|
||||
and (nxp.param2 == 0 or nxp.param2 == 2) then
|
||||
pxp=1
|
||||
end
|
||||
|
||||
if (string.find(nzm.name, "pipeworks:valve") ~= nil)
|
||||
and (nzm.param2 == 1 or nzm.param2 == 3) then
|
||||
pzm=1
|
||||
end
|
||||
|
||||
if (string.find(nzp.name, "pipeworks:valve") ~= nil)
|
||||
and (nzp.param2 == 1 or nzp.param2 == 3) then
|
||||
pzp=1
|
||||
end
|
||||
|
||||
-- ...flow sensors...
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:flow_sensor") ~= nil)
|
||||
and (nxm.param2 == 0 or nxm.param2 == 2) then
|
||||
pxm=1
|
||||
end
|
||||
|
||||
if (string.find(nxp.name, "pipeworks:flow_sensor") ~= nil)
|
||||
and (nxp.param2 == 0 or nxp.param2 == 2) then
|
||||
pxp=1
|
||||
end
|
||||
|
||||
if (string.find(nzm.name, "pipeworks:flow_sensor") ~= nil)
|
||||
and (nzm.param2 == 1 or nzm.param2 == 3) then
|
||||
pzm=1
|
||||
end
|
||||
|
||||
if (string.find(nzp.name, "pipeworks:flow_sensor") ~= nil)
|
||||
and (nzp.param2 == 1 or nzp.param2 == 3) then
|
||||
pzp=1
|
||||
end
|
||||
|
||||
-- ...spigots...
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:spigot") ~= nil)
|
||||
and nxm.param2 == 1 then
|
||||
pxm=1
|
||||
end
|
||||
|
||||
if (string.find(nxp.name, "pipeworks:spigot") ~= nil)
|
||||
and nxp.param2 == 3 then
|
||||
pxp=1
|
||||
end
|
||||
|
||||
if (string.find(nzm.name, "pipeworks:spigot") ~= nil)
|
||||
and nzm.param2 == 0 then
|
||||
pzm=1
|
||||
end
|
||||
|
||||
if (string.find(nzp.name, "pipeworks:spigot") ~= nil)
|
||||
and nzp.param2 == 2 then
|
||||
pzp=1
|
||||
end
|
||||
|
||||
-- ...sealed pipe entry/exit...
|
||||
|
||||
if (string.find(nxm.name, "pipeworks:entry_panel") ~= nil)
|
||||
and (nxm.param2 == 1 or nxm.param2 == 3) then
|
||||
pxm=1
|
||||
end
|
||||
|
||||
if (string.find(nxp.name, "pipeworks:entry_panel") ~= nil)
|
||||
and (nxp.param2 == 1 or nxp.param2 == 3) then
|
||||
pxp=1
|
||||
end
|
||||
|
||||
if (string.find(nzm.name, "pipeworks:entry_panel") ~= nil)
|
||||
and (nzm.param2 == 0 or nzm.param2 == 2) then
|
||||
pzm=1
|
||||
end
|
||||
|
||||
if (string.find(nzp.name, "pipeworks:entry_panel") ~= nil)
|
||||
and (nzp.param2 == 0 or nzp.param2 == 2) then
|
||||
pzp=1
|
||||
end
|
||||
|
||||
if (string.find(nym.name, "pipeworks:entry_panel") ~= nil)
|
||||
and nym.param2 == 13 then
|
||||
pym=1
|
||||
end
|
||||
|
||||
if (string.find(nyp.name, "pipeworks:entry_panel") ~= nil)
|
||||
and nyp.param2 == 13 then
|
||||
pyp=1
|
||||
end
|
||||
|
||||
|
||||
-- ...pumps, grates...
|
||||
|
||||
if (string.find(nym.name, "pipeworks:grating") ~= nil) or
|
||||
(string.find(nym.name, "pipeworks:pump") ~= nil) then
|
||||
pym=1
|
||||
end
|
||||
|
||||
-- ...fountainheads...
|
||||
|
||||
if (string.find(nyp.name, "pipeworks:fountainhead") ~= nil) then
|
||||
pyp=1
|
||||
end
|
||||
|
||||
-- ... and storage tanks.
|
||||
|
||||
if (string.find(nym.name, "pipeworks:storage_tank_") ~= nil) then
|
||||
pym=1
|
||||
end
|
||||
|
||||
if (string.find(nyp.name, "pipeworks:storage_tank_") ~= nil) then
|
||||
pyp=1
|
||||
end
|
||||
|
||||
-- ...extra devices specified via the function's parameters
|
||||
-- ...except that this part is not implemented yet
|
||||
--
|
||||
-- xxx = nxm, nxp, nym, nyp, nzm, or nzp depending on the direction to check
|
||||
-- yyy = pxm, pxp, pym, pyp, pzm, or pzp accordingly.
|
||||
--
|
||||
-- if string.find(xxx.name, "modname:nodename") ~= nil then
|
||||
-- yyy = 1
|
||||
-- end
|
||||
--
|
||||
-- for example:
|
||||
--
|
||||
-- if string.find(nym.name, "aero:outlet") ~= nil then
|
||||
-- pym = 1
|
||||
-- end
|
||||
--
|
||||
|
||||
return pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp
|
||||
end
|
||||
|
||||
function pipeworks.look_for_stackable_tanks(pos)
|
||||
local tym = minetest.get_node({ x=pos.x , y=pos.y-1, z=pos.z })
|
||||
|
||||
if string.find(tym.name, "pipeworks:storage_tank_") ~= nil or
|
||||
string.find(tym.name, "pipeworks:expansion_tank_") ~= nil then
|
||||
minetest.add_node(pos, { name = "pipeworks:expansion_tank_0", param2 = tym.param2})
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
-- autorouting for pneumatic tubes
|
||||
|
||||
local function in_table(table,element)
|
||||
for _,el in ipairs(table) do
|
||||
if el==element then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function is_tube(nodename)
|
||||
return in_table(pipeworks.tubenodes,nodename)
|
||||
end
|
||||
|
||||
if pipeworks == nil then
|
||||
pipeworks = {}
|
||||
end
|
||||
|
||||
--a function for determining which side of the node we are on
|
||||
local function nodeside(node, tubedir)
|
||||
if node and (node.param2 < 0 or node.param2 > 23) then node.param2 = 0 end
|
||||
|
||||
--get a vector pointing back
|
||||
local backdir = minetest.facedir_to_dir(node.param2)
|
||||
|
||||
--check whether the vector is equivalent to the tube direction; if it is, the tube's on the backside
|
||||
if backdir.x == tubedir.x and backdir.y == tubedir.y and backdir.z == tubedir.z then
|
||||
return "back"
|
||||
end
|
||||
|
||||
--check whether the vector is antiparallel with the tube direction; that indicates the front
|
||||
if backdir.x == -tubedir.x and backdir.y == -tubedir.y and backdir.z == -tubedir.z then
|
||||
return "front"
|
||||
end
|
||||
|
||||
--facedir is defined in terms of the top-bottom axis of the node; we'll take advantage of that
|
||||
local topdir = ({[0]={x=0, y=1, z=0},
|
||||
{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}})[math.floor(node.param2/4)]
|
||||
|
||||
--is this the top?
|
||||
if topdir.x == tubedir.x and topdir.y == tubedir.y and topdir.z == tubedir.z then
|
||||
return "top"
|
||||
end
|
||||
|
||||
--or the bottom?
|
||||
if topdir.x == -tubedir.x and topdir.y == -tubedir.y and topdir.z == -tubedir.z then
|
||||
return "bottom"
|
||||
end
|
||||
|
||||
--we shall apply some maths to obtain the right-facing vector
|
||||
local rightdir = {x=topdir.y*backdir.z - backdir.y*topdir.z,
|
||||
y=topdir.z*backdir.x - backdir.z*topdir.x,
|
||||
z=topdir.x*backdir.y - backdir.x*topdir.y}
|
||||
|
||||
--is this the right side?
|
||||
if rightdir.x == tubedir.x and rightdir.y == tubedir.y and rightdir.z == tubedir.z then
|
||||
return "right"
|
||||
end
|
||||
|
||||
--or the left?
|
||||
if rightdir.x == -tubedir.x and rightdir.y == -tubedir.y and rightdir.z == -tubedir.z then
|
||||
return "left"
|
||||
end
|
||||
|
||||
--we should be done by now; initiate panic mode
|
||||
minetest.log("error", "nodeside has been confused by its parameters; see pipeworks autoplace_tubes.lua, line 78")
|
||||
end
|
||||
|
||||
local vts = {0, 3, 1, 4, 2, 5}
|
||||
local tube_table = {[0] = 1, 2, 2, 4, 2, 4, 4, 5, 2, 3, 4, 6, 4, 6, 5, 7, 2, 4, 3, 6, 4, 5, 6, 7, 4, 6, 6, 8, 5, 7, 7, 9, 2, 4, 4, 5, 3, 6, 6, 7, 4, 6, 5, 7, 6, 8, 7, 9, 4, 5, 6, 7, 6, 7, 8, 9, 5, 7, 7, 9, 7, 9, 9, 10}
|
||||
local tube_table_facedirs = {[0] = 0, 0, 5, 0, 3, 4, 3, 0, 2, 0, 2, 0, 6, 4, 3, 0, 7, 12, 5, 12, 7, 4, 5, 5, 18, 20, 16, 0, 7, 4, 7, 0, 1, 8, 1, 1, 1, 13, 1, 1, 10, 8, 2, 2, 17, 4, 3, 6, 9, 9, 9, 9, 21, 13, 1, 1, 10, 10, 11, 2, 19, 4, 3, 0}
|
||||
local function tube_autoroute(pos)
|
||||
local active = {0, 0, 0, 0, 0, 0}
|
||||
local nctr = minetest.get_node(pos)
|
||||
if not is_tube(nctr.name) then return end
|
||||
|
||||
local adjustments = {
|
||||
{ x=-1, y=0, z=0 },
|
||||
{ x=1, y=0, z=0 },
|
||||
{ x=0, y=-1, z=0 },
|
||||
{ x=0, y=1, z=0 },
|
||||
{ x=0, y=0, z=-1 },
|
||||
{ x=0, y=0, z=1 }
|
||||
}
|
||||
-- xm = 1, xp = 2, ym = 3, yp = 4, zm = 5, zp = 6
|
||||
|
||||
local positions = {}
|
||||
local nodes = {}
|
||||
for i,adj in ipairs(adjustments) do
|
||||
positions[i] = {x=pos.x+adj.x, y=pos.y+adj.y, z=pos.z+adj.z}
|
||||
nodes[i] = minetest.get_node(positions[i])
|
||||
end
|
||||
|
||||
for i,node in ipairs(nodes) do
|
||||
local idef = minetest.registered_nodes[node.name]
|
||||
-- handle the tubes themselves
|
||||
if is_tube(node.name) then
|
||||
active[i] = 1
|
||||
-- handle new style connectors
|
||||
elseif idef and idef.tube and idef.tube.connect_sides then
|
||||
local dir = adjustments[i]
|
||||
if idef.tube.connect_sides[nodeside(node, {x=-dir.x, y=-dir.y, z=-dir.z})] then active[i] = 1 end
|
||||
end
|
||||
end
|
||||
|
||||
-- all sides checked, now figure which tube to use.
|
||||
|
||||
local nodedef = minetest.registered_nodes[nctr.name]
|
||||
local basename = nodedef.basename
|
||||
local newname
|
||||
if nodedef.style == "old" then
|
||||
local nsurround = ""
|
||||
for i,n in ipairs(active) do
|
||||
nsurround = nsurround .. n
|
||||
end
|
||||
nctr.name = basename.."_"..nsurround
|
||||
elseif nodedef.style == "6d" then
|
||||
local s = 0
|
||||
for i,n in ipairs(active) do
|
||||
if n == 1 then
|
||||
s = s+2^vts[i]
|
||||
end
|
||||
end
|
||||
nctr.name = basename.."_"..tube_table[s]
|
||||
nctr.param2 = tube_table_facedirs[s]
|
||||
end
|
||||
minetest.swap_node(pos, nctr)
|
||||
end
|
||||
|
||||
function pipeworks.scan_for_tube_objects(pos)
|
||||
if not pos or not pos.x or not pos.y or not pos.z then return end
|
||||
tube_autoroute({ x=pos.x-1, y=pos.y , z=pos.z })
|
||||
tube_autoroute({ x=pos.x+1, y=pos.y , z=pos.z })
|
||||
tube_autoroute({ x=pos.x , y=pos.y-1, z=pos.z })
|
||||
tube_autoroute({ x=pos.x , y=pos.y+1, z=pos.z })
|
||||
tube_autoroute({ x=pos.x , y=pos.y , z=pos.z-1 })
|
||||
tube_autoroute({ x=pos.x , y=pos.y , z=pos.z+1 })
|
||||
tube_autoroute(pos)
|
||||
end
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
||||
if minetest.registered_items[newnode.name]
|
||||
and minetest.registered_items[newnode.name].tube
|
||||
and minetest.registered_items[newnode.name].tube.connect_sides then
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||
if minetest.registered_items[oldnode.name]
|
||||
and minetest.registered_items[oldnode.name].tube
|
||||
and minetest.registered_items[oldnode.name].tube.connect_sides then
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
if minetest.get_modpath("mesecons_mvps") ~= nil then
|
||||
mesecon:register_on_mvps_move(function(moved_nodes)
|
||||
for _, n in ipairs(moved_nodes) do
|
||||
pipeworks.scan_for_tube_objects(n.pos)
|
||||
pipeworks.scan_for_tube_objects(n.oldpos)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
@ -1,180 +1,158 @@
|
|||
-- this bit of code modifies the default chests and furnaces to be compatible
|
||||
-- with pipeworks.
|
||||
|
||||
default.furnace_inactive_formspec =
|
||||
"size[8,9]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
"list[current_name;src;2,1;1,1;]"..
|
||||
"list[current_name;dst;5,1;2,2;]"..
|
||||
"list[current_player;main;0,5;8,4;]"
|
||||
function pipeworks.clone_node(name)
|
||||
local node2 = {}
|
||||
local node = minetest.registered_nodes[name]
|
||||
for k, v in pairs(node) do
|
||||
node2[k] = v
|
||||
end
|
||||
return node2
|
||||
end
|
||||
|
||||
minetest.register_node(":default:furnace", {
|
||||
description = "Furnace",
|
||||
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_front.png"},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2,tubedevice=1,tubedevice_receiver=1},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
if direction.y==1 then
|
||||
local furnace = pipeworks.clone_node("default:furnace")
|
||||
furnace.tiles[1] = "default_furnace_top.png^pipeworks_tube_connection_stony.png"
|
||||
furnace.tiles[2] = "default_furnace_bottom.png^pipeworks_tube_connection_stony.png"
|
||||
furnace.tiles[3] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
|
||||
furnace.tiles[4] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
|
||||
furnace.tiles[5] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
|
||||
-- note we don't redefine entry 6 ( front)
|
||||
furnace.groups.tubedevice = 1
|
||||
furnace.groups.tubedevice_receiver = 1
|
||||
furnace.tube = {
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if direction.y == 1 then
|
||||
return inv:add_item("fuel",stack)
|
||||
else
|
||||
return inv:add_item("src",stack)
|
||||
end
|
||||
end,
|
||||
can_insert=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
if direction.y==1 then
|
||||
return inv:room_for_item("fuel",stack)
|
||||
elseif direction.y==-1 then
|
||||
return inv:room_for_item("src",stack)
|
||||
can_insert = function(pos,node,stack,direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if direction.y == 1 then
|
||||
return inv:room_for_item("fuel", stack)
|
||||
else
|
||||
return 0
|
||||
return inv:room_for_item("src", stack)
|
||||
end
|
||||
end,
|
||||
input_inventory="dst"},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
||||
meta:set_string("infotext", "Furnace")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("fuel") then
|
||||
return false
|
||||
elseif not inv:is_empty("dst") then
|
||||
return false
|
||||
elseif not inv:is_empty("src") then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
tube_scanforobjects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
tube_scanforobjects(pos)
|
||||
input_inventory = "dst",
|
||||
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
|
||||
}
|
||||
furnace.after_place_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
furnace.after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node(":default:furnace_active", {
|
||||
description = "Furnace",
|
||||
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_front_active.png"},
|
||||
paramtype2 = "facedir",
|
||||
light_source = 8,
|
||||
drop = "default:furnace",
|
||||
groups = {cracky=2, not_in_creative_inventory=1,tubedevice=1,tubedevice_receiver=1},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
if direction.y==1 then
|
||||
return inv:add_item("fuel",stack)
|
||||
else
|
||||
return inv:add_item("src",stack)
|
||||
end
|
||||
end,
|
||||
can_insert=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
if direction.y==1 then
|
||||
return inv:room_for_item("fuel",stack)
|
||||
elseif direction.y==-1 then
|
||||
return inv:room_for_item("src",stack)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
input_inventory="dst"},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
||||
meta:set_string("infotext", "Furnace");
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("fuel") then
|
||||
return false
|
||||
elseif not inv:is_empty("dst") then
|
||||
return false
|
||||
elseif not inv:is_empty("src") then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
tube_scanforobjects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
tube_scanforobjects(pos)
|
||||
end
|
||||
})
|
||||
minetest.register_node(":default:furnace", furnace)
|
||||
|
||||
minetest.register_node(":default:chest", {
|
||||
description = "Chest",
|
||||
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
|
||||
"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,tubedevice_receiver=1},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:add_item("main",stack)
|
||||
local furnace_active = pipeworks.clone_node("default:furnace_active")
|
||||
furnace_active.tiles[1] = "default_furnace_top.png^pipeworks_tube_connection_stony.png"
|
||||
furnace_active.tiles[2] = "default_furnace_bottom.png^pipeworks_tube_connection_stony.png"
|
||||
furnace_active.tiles[3] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
|
||||
furnace_active.tiles[4] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
|
||||
furnace_active.tiles[5] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
|
||||
-- note we don't redefine entry 6 (front)
|
||||
furnace_active.groups.tubedevice = 1
|
||||
furnace_active.groups.tubedevice_receiver = 1
|
||||
furnace_active.tube = {
|
||||
insert_object = function(pos,node,stack,direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if direction.y == 1 then
|
||||
return inv:add_item("fuel", stack)
|
||||
else
|
||||
return inv:add_item("src", stack)
|
||||
end
|
||||
end,
|
||||
can_insert=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:room_for_item("main",stack)
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if direction.y == 1 then
|
||||
return inv:room_for_item("fuel", stack)
|
||||
else
|
||||
return inv:room_for_item("src", stack)
|
||||
end
|
||||
end,
|
||||
input_inventory="main"},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"size[8,9]"..
|
||||
"list[current_name;main;0,0;8,4;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
meta:set_string("infotext", "Chest")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in chest at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff to chest at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from chest at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
tube_scanforobjects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
tube_scanforobjects(pos)
|
||||
input_inventory = "dst",
|
||||
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
|
||||
}
|
||||
furnace_active.after_place_node= function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
})
|
||||
furnace_active.after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
|
||||
minetest.register_node(":default:furnace_active", furnace_active)
|
||||
|
||||
|
||||
local chest = pipeworks.clone_node("default:chest")
|
||||
chest.tiles[1] = "default_chest_top.png^pipeworks_tube_connection_wooden.png"
|
||||
chest.tiles[2] = "default_chest_top.png^pipeworks_tube_connection_wooden.png"
|
||||
chest.tiles[3] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
|
||||
chest.tiles[4] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
|
||||
chest.tiles[5] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
|
||||
-- note we don't redefine entry 6 (front).
|
||||
chest.groups.tubedevice = 1
|
||||
chest.groups.tubedevice_receiver = 1
|
||||
chest.tube = {
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:add_item("main", stack)
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:room_for_item("main", stack)
|
||||
end,
|
||||
input_inventory = "main",
|
||||
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
|
||||
}
|
||||
chest.after_place_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
chest.after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
|
||||
minetest.register_node(":default:chest", chest)
|
||||
|
||||
|
||||
local chest_locked = pipeworks.clone_node("default:chest_locked")
|
||||
chest_locked.tiles[1] = "default_chest_top.png^pipeworks_tube_connection_wooden.png"
|
||||
chest_locked.tiles[2] = "default_chest_top.png^pipeworks_tube_connection_wooden.png"
|
||||
chest_locked.tiles[3] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
|
||||
chest_locked.tiles[4] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
|
||||
chest_locked.tiles[5] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
|
||||
-- note we don't redefine entry 6 (front).
|
||||
chest_locked.groups.tubedevice = 1
|
||||
chest_locked.groups.tubedevice_receiver = 1
|
||||
chest_locked.tube = {
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:add_item("main", stack)
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:room_for_item("main", stack)
|
||||
end,
|
||||
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
|
||||
}
|
||||
local old_after_place = minetest.registered_nodes["default:chest_locked"].after_place_node
|
||||
chest_locked.after_place_node = function(pos, placer)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
old_after_place(pos, placer)
|
||||
end
|
||||
chest_locked.after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
|
||||
minetest.register_node(":default:chest_locked", chest_locked)
|
||||
|
|
|
@ -1,168 +1,303 @@
|
|||
-- Crafting recipes for pipeworks
|
||||
-- Crafting recipes for pipes
|
||||
|
||||
-- If the technic mod is present, then don't bother registering these recipes
|
||||
-- as that mod supplies its own.
|
||||
|
||||
if io.open(minetest.get_modpath("pipeworks").."/../technic/init.lua", "r") == nil then
|
||||
|
||||
-- If homedecor is not installed, we need to register a few of its crafts
|
||||
-- manually so we can use them.
|
||||
|
||||
if minetest.get_modpath("homedecor") == nil then
|
||||
|
||||
minetest.register_craftitem(":homedecor:plastic_sheeting", {
|
||||
description = "Plastic sheet",
|
||||
inventory_image = "pipeworks_plastic_sheeting.png",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "homedecor:plastic_sheeting",
|
||||
recipe = "default:junglegrass",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = 'fuel',
|
||||
recipe = 'homedecor:plastic_sheeting',
|
||||
burntime = 30,
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:pipe_110000_empty 12",
|
||||
recipe = {
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "", "", "" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:pump_off 2",
|
||||
recipe = {
|
||||
{ "default:stone", "default:steel_ingot", "default:stone" },
|
||||
{ "moreores:copper_ingot", "default:mese_crystal_fragment", "moreores:copper_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:valve_off 2",
|
||||
recipe = {
|
||||
{ "", "default:stick", "" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "", "default:steel_ingot", "" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:storage_tank_0 2",
|
||||
recipe = {
|
||||
{ "", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:glass", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:grating 2",
|
||||
recipe = {
|
||||
{ "default:steel_ingot", "", "default:steel_ingot" },
|
||||
{ "", "default:steel_ingot", "" },
|
||||
{ "default:steel_ingot", "", "default:steel_ingot" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:spigot 3",
|
||||
recipe = {
|
||||
{ "pipeworks:pipe_110000_empty", "" },
|
||||
{ "", "pipeworks:pipe_110000_empty" },
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:tube 12",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "", "", "" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:mese_tube_000000 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "", "default:mese_crystal", "" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
type = "shapeless",
|
||||
output = "pipeworks:mese_tube_000000",
|
||||
recipe = {
|
||||
"pipeworks:tube_000000",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment"
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:detector_tube_off_000000 2",
|
||||
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( {
|
||||
output = "pipeworks:accelerator_tube_000000 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:mese_crystal_fragment", "default:steel_ingot", "default:mese_crystal_fragment" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:teleport_tube_000000 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:desert_stone", "default:mese_block", "default:desert_stone" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:sand_tube_000000 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:sand", "default:sand", "default:sand" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:filter 2",
|
||||
recipe = {
|
||||
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
|
||||
{ "default:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:entry_panel 2",
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:pipe_1_empty 12",
|
||||
recipe = {
|
||||
{ "", "default:steel_ingot", "" },
|
||||
{ "", "pipeworks:pipe_110000_empty", "" },
|
||||
{ "", "default:steel_ingot", "" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "", "", "" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:spigot 3",
|
||||
recipe = {
|
||||
{ "pipeworks:pipe_1_empty", "" },
|
||||
{ "", "pipeworks:pipe_1_empty" },
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:entry_panel_empty 2",
|
||||
recipe = {
|
||||
{ "", "default:steel_ingot", "" },
|
||||
{ "", "pipeworks:pipe_1_empty", "" },
|
||||
{ "", "default:steel_ingot", "" },
|
||||
},
|
||||
})
|
||||
|
||||
-- Various ancillary pipe devices
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:pump_off 2",
|
||||
recipe = {
|
||||
{ "default:stone", "default:steel_ingot", "default:stone" },
|
||||
{ "moreores:copper_ingot", "default:mese_crystal_fragment", "moreores:copper_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:valve_off_empty 2",
|
||||
recipe = {
|
||||
{ "", "default:stick", "" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "", "default:steel_ingot", "" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:storage_tank_0 2",
|
||||
recipe = {
|
||||
{ "", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:glass", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:grating 2",
|
||||
recipe = {
|
||||
{ "default:steel_ingot", "", "default:steel_ingot" },
|
||||
{ "", "pipeworks:pipe_1_empty", "" },
|
||||
{ "default:steel_ingot", "", "default:steel_ingot" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:flow_sensor_empty 2",
|
||||
recipe = {
|
||||
{ "pipeworks:pipe_1_empty", "mesecons:mesecon", "pipeworks:pipe_1_empty" },
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:fountainhead 2",
|
||||
recipe = {
|
||||
{ "pipeworks:pipe_1_empty" },
|
||||
{ "pipeworks:pipe_1_empty" }
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- Crafting recipes for pneumatic tubes
|
||||
|
||||
-- If homedecor is not installed, we need to register its crafting chain for
|
||||
-- plastic sheeting so that pipeworks remains compatible with it.
|
||||
|
||||
if minetest.get_modpath("homedecor") == nil then
|
||||
|
||||
minetest.register_craftitem(":homedecor:plastic_sheeting", {
|
||||
description = "Plastic sheet",
|
||||
inventory_image = "homedecor_plastic_sheeting.png",
|
||||
})
|
||||
|
||||
minetest.register_craftitem(":homedecor:plastic_base", {
|
||||
description = "Unprocessed Plastic base",
|
||||
wield_image = "homedecor_plastic_base.png",
|
||||
inventory_image = "homedecor_plastic_base_inv.png",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = 'homedecor:plastic_base 4',
|
||||
recipe = { "group:leaves",
|
||||
"group:leaves",
|
||||
"group:leaves",
|
||||
"group:leaves",
|
||||
"group:leaves",
|
||||
"group:leaves"
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "homedecor:plastic_sheeting",
|
||||
recipe = "homedecor:plastic_base",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = 'fuel',
|
||||
recipe = 'homedecor:plastic_base',
|
||||
burntime = 30,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = 'fuel',
|
||||
recipe = 'homedecor:plastic_sheeting',
|
||||
burntime = 30,
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:one_way_tube 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:tube_1 6",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "", "", "" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:mese_tube_1 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "", "default:mese_crystal", "" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
type = "shapeless",
|
||||
output = "pipeworks:mese_tube_000000",
|
||||
recipe = {
|
||||
"pipeworks:tube_1",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment"
|
||||
},
|
||||
})
|
||||
|
||||
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( {
|
||||
output = "pipeworks:detector_tube_off_1 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "mesecons:mesecon", "mesecons_materials:silicon", "mesecons:mesecon" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:accelerator_tube_1 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:mese_crystal_fragment", "default:steel_ingot", "default:mese_crystal_fragment" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:teleport_tube_1 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:desert_stone", "default:mese_block", "default:desert_stone" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:sand_tube_1 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:sand", "default:sand", "default:sand" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:sand_tube_1 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:desert_sand", "default:desert_sand", "default:desert_sand" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:sand_tube_1",
|
||||
recipe = {
|
||||
{ "default:desert_sand", "pipeworks:tube_1", "default:desert_sand" },
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:mese_sand_tube_1 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:sand", "default:mese_crystal", "default:sand" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:mese_sand_tube_1 2",
|
||||
recipe = {
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||
{ "default:desert_sand", "default:mese_crystal", "default:desert_sand" },
|
||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:crossing_tube_1 5",
|
||||
recipe = {
|
||||
{ "", "pipeworks:tube_1", "" },
|
||||
{ "pipeworks:tube_1", "pipeworks:tube_1", "pipeworks:tube_1" },
|
||||
{ "", "pipeworks:tube_1", "" }
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft( {
|
||||
type = "shapeless",
|
||||
output = "pipeworks:mese_sand_tube_1",
|
||||
recipe = {
|
||||
"pipeworks:sand_tube_1",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment",
|
||||
"default:mese_crystal_fragment"
|
||||
},
|
||||
})
|
||||
|
||||
-- Various ancillary tube devices
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:filter 2",
|
||||
recipe = {
|
||||
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
|
||||
{ "default:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:mese_filter 2",
|
||||
recipe = {
|
||||
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
|
||||
{ "default:stick", "default:mese", "homedecor:plastic_sheeting" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:autocrafter 2",
|
||||
recipe = {
|
||||
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" },
|
||||
{ "homedecor:plastic_sheeting", "default:steel_ingot", "homedecor:plastic_sheeting" },
|
||||
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" }
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
-- Various settings
|
||||
|
||||
pipeworks.enable_pipes = true
|
||||
pipeworks.enable_autocrafter = true
|
||||
pipeworks.enable_deployer = true
|
||||
pipeworks.enable_node_breaker = true
|
||||
pipeworks.enable_teleport_tube = true
|
||||
pipeworks.enable_pipe_devices = true
|
||||
pipeworks.enable_redefines = true
|
||||
pipeworks.enable_mese_tube = true
|
||||
pipeworks.enable_detector_tube = true
|
||||
pipeworks.enable_conductor_tube = true
|
||||
pipeworks.enable_accelerator_tube = true
|
||||
pipeworks.enable_crossing_tube = true
|
||||
pipeworks.enable_sand_tube = true
|
||||
pipeworks.enable_mese_sand_tube = true
|
||||
pipeworks.enable_one_way_tube = true
|
||||
pipeworks.enable_cyclic_mode = true
|
|
@ -1,2 +1,3 @@
|
|||
default
|
||||
|
||||
mesecons?
|
||||
mesecons_mvps?
|
||||
|
|
|
@ -1,64 +1,114 @@
|
|||
|
||||
--register aliases for when someone had technic installed, but then uninstalled it but not pipeworks
|
||||
minetest.register_alias("technic:deployer_off", "pipeworks:deployer_off")
|
||||
minetest.register_alias("technic:deployer_on", "pipeworks:deployer_on")
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'pipeworks:deployer_off 1',
|
||||
recipe = {
|
||||
{'default:wood', 'default:chest','default:wood'},
|
||||
{'group:wood', 'default:chest','group:wood'},
|
||||
{'default:stone', 'mesecons:piston','default:stone'},
|
||||
{'default:stone', 'mesecons:mesecon','default:stone'},
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
deployer_on = function(pos, node)
|
||||
local pos1={}
|
||||
pos1.x=pos.x
|
||||
pos1.y=pos.y
|
||||
pos1.z=pos.z
|
||||
local pos2={}
|
||||
pos2.x=pos.x
|
||||
pos2.y=pos.y
|
||||
pos2.z=pos.z
|
||||
if node.param2==3 then
|
||||
pos1.x=pos1.x+1
|
||||
pos2.x=pos2.x+2
|
||||
end
|
||||
if node.param2==2 then
|
||||
pos1.z=pos1.z+1
|
||||
pos2.z=pos2.z+2
|
||||
end
|
||||
if node.param2==1 then
|
||||
pos1.x=pos1.x-1
|
||||
pos2.x=pos2.x-2
|
||||
end
|
||||
if node.param2==0 then
|
||||
pos1.z=pos1.z-1
|
||||
pos2.z=pos2.z-2
|
||||
end
|
||||
local function swap_node(pos, name)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
if node.name == "pipeworks:deployer_off" then
|
||||
hacky_swap_node(pos,"pipeworks:deployer_on")
|
||||
nodeupdate(pos)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
|
||||
local inv = meta:get_inventory()
|
||||
local invlist=inv:get_list("main")
|
||||
for i,stack in ipairs(invlist) do
|
||||
local function delay(x)
|
||||
return (function() return x end)
|
||||
end
|
||||
|
||||
if stack:get_name() ~=nil and stack:get_name() ~="" and minetest.env:get_node(pos1).name == "air" then
|
||||
local placer={}
|
||||
function placer:get_player_name() return "deployer" end
|
||||
function placer:getpos() return pos end
|
||||
local stack2=minetest.item_place(stack,placer,{type="node", under=pos1, above=pos2})
|
||||
invlist[i]=stack2
|
||||
inv:set_list("main",invlist)
|
||||
local function deployer_on(pos, node)
|
||||
if node.name ~= "pipeworks:deployer_off" then
|
||||
return
|
||||
end
|
||||
|
||||
--locate the above and under positions
|
||||
local dir = minetest.facedir_to_dir(node.param2)
|
||||
local pos_under, pos_above = {x = pos.x - dir.x, y = pos.y - dir.y, z = pos.z - dir.z}, {x = pos.x - 2*dir.x, y = pos.y - 2*dir.y, z = pos.z - 2*dir.z}
|
||||
|
||||
swap_node(pos, "pipeworks:deployer_on")
|
||||
nodeupdate(pos)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local invlist = inv:get_list("main")
|
||||
for i, stack in ipairs(invlist) do
|
||||
if stack:get_name() ~= nil and stack:get_name() ~= "" then--and minetest.get_node(pos_under).name == "air" then --obtain the first non-empty item slot
|
||||
local pitch
|
||||
local yaw
|
||||
if dir.z < 0 then
|
||||
yaw = 0
|
||||
pitch = 0
|
||||
elseif dir.z > 0 then
|
||||
yaw = math.pi
|
||||
pitch = 0
|
||||
elseif dir.x < 0 then
|
||||
yaw = 3*math.pi/2
|
||||
pitch = 0
|
||||
elseif dir.x > 0 then
|
||||
yaw = math.pi/2
|
||||
pitch = 0
|
||||
elseif dir.y > 0 then
|
||||
yaw = 0
|
||||
pitch = -math.pi/2
|
||||
else
|
||||
yaw = 0
|
||||
pitch = math.pi/2
|
||||
end
|
||||
local placer = {
|
||||
get_inventory_formspec = delay(meta:get_string("formspec")),
|
||||
get_look_dir = delay({x = -dir.x, y = -dir.y, z = -dir.z}),
|
||||
get_look_pitch = delay(pitch),
|
||||
get_look_yaw = delay(yaw),
|
||||
get_player_control = delay({jump=false, right=false, left=false, LMB=false, RMB=false, sneak=false, aux1=false, down=false, up=false}),
|
||||
get_player_control_bits = delay(0),
|
||||
get_player_name = delay(meta:get_string("owner")),
|
||||
is_player = delay(true),
|
||||
set_inventory_formspec = delay(),
|
||||
getpos = delay({x = pos.x, y = pos.y - 1.5, z = pos.z}), -- Player height
|
||||
get_hp = delay(20),
|
||||
get_inventory = delay(inv),
|
||||
get_wielded_item = delay(stack),
|
||||
get_wield_index = delay(i),
|
||||
get_wield_list = delay("main"),
|
||||
moveto = delay(),
|
||||
punch = delay(),
|
||||
remove = delay(),
|
||||
right_click = delay(),
|
||||
setpos = delay(),
|
||||
set_hp = delay(),
|
||||
set_properties = delay(),
|
||||
set_wielded_item = function(self, item) inv:set_stack("main", i, item) end,
|
||||
set_animation = delay(),
|
||||
set_attach = delay(),
|
||||
set_detach = delay(),
|
||||
set_bone_position = delay(),
|
||||
}
|
||||
local pointed_thing = {type="node", under=pos_under, above=pos_above}
|
||||
local stack2
|
||||
if minetest.registered_items[stack:get_name()] then
|
||||
stack2 = minetest.registered_items[stack:get_name()].on_place(stack, placer, pointed_thing)
|
||||
end
|
||||
--if minetest.setting_getbool("creative_mode") and not minetest.get_modpath("unified_inventory") then --infinite stacks ahoy!
|
||||
-- stack2:take_item()
|
||||
--end
|
||||
inv:set_stack("main", i, stack2)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
deployer_off = function(pos, node)
|
||||
local deployer_off = function(pos, node)
|
||||
if node.name == "pipeworks:deployer_on" then
|
||||
hacky_swap_node(pos,"pipeworks:deployer_off")
|
||||
swap_node(pos, "pipeworks:deployer_off")
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
@ -67,24 +117,28 @@ minetest.register_node("pipeworks:deployer_off", {
|
|||
description = "Deployer",
|
||||
tile_images = {"pipeworks_deployer_top.png","pipeworks_deployer_bottom.png","pipeworks_deployer_side2.png","pipeworks_deployer_side1.png",
|
||||
"pipeworks_deployer_back.png","pipeworks_deployer_front_off.png"},
|
||||
mesecons = {effector={action_on=deployer_on,action_off=deployer_off}},
|
||||
mesecons = {effector={rules=pipeworks.rules_all,action_on=deployer_on,action_off=deployer_off}},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:add_item("main",stack)
|
||||
end,
|
||||
can_insert=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:room_for_item("main",stack)
|
||||
end,
|
||||
input_inventory="main"},
|
||||
input_inventory="main",
|
||||
connect_sides={back=1},
|
||||
can_remove = function(pos, node, stack, dir)
|
||||
return stack:get_count()
|
||||
end},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"label[0,0;Deployer]"..
|
||||
|
@ -94,38 +148,85 @@ minetest.register_node("pipeworks:deployer_off", {
|
|||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 3*3)
|
||||
end,
|
||||
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
|
||||
after_place_node = function (pos, placer)
|
||||
pipeworks.scan_for_tube_objects(pos, placer)
|
||||
local placer_pos = placer:getpos()
|
||||
|
||||
--correct for the player's height
|
||||
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
|
||||
|
||||
--correct for 6d facedir
|
||||
if placer_pos then
|
||||
local dir = {
|
||||
x = pos.x - placer_pos.x,
|
||||
y = pos.y - placer_pos.y,
|
||||
z = pos.z - placer_pos.z
|
||||
}
|
||||
local node = minetest.get_node(pos)
|
||||
node.param2 = minetest.dir_to_facedir(dir, true)
|
||||
minetest.set_node(pos, node)
|
||||
minetest.log("action", "real (6d) facedir: " .. node.param2)
|
||||
end
|
||||
|
||||
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
|
||||
end,
|
||||
after_dig_node = pipeworks.scan_for_tube_objects,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("pipeworks:deployer_on", {
|
||||
description = "Deployer",
|
||||
tile_images = {"pipeworks_deployer_top.png","pipeworks_deployer_bottom.png","pipeworks_deployer_side2.png","pipeworks_deployer_side1.png",
|
||||
"pipeworks_deployer_back.png","pipeworks_deployer_front_on.png"},
|
||||
mesecons = {effector={action_on=deployer_on,action_off=deployer_off}},
|
||||
mesecons = {effector={rules=pipeworks.rules_all,action_on=deployer_on,action_off=deployer_off}},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:add_item("main",stack)
|
||||
end,
|
||||
can_insert=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:room_for_item("main",stack)
|
||||
end,
|
||||
input_inventory="main"},
|
||||
input_inventory="main",
|
||||
connect_sides={back=1},
|
||||
can_remove = function(pos, node, stack, dir)
|
||||
return stack:get_count()
|
||||
end},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
tubelike=1,
|
||||
drop = "pipeworks:deployer_off",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1,not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"label[0,0;Deployer]"..
|
||||
|
@ -136,23 +237,52 @@ minetest.register_node("pipeworks:deployer_on", {
|
|||
inv:set_size("main", 3*3)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
after_place_node = function (pos, placer)
|
||||
pipeworks.scan_for_tube_objects(pos, placer)
|
||||
local placer_pos = placer:getpos()
|
||||
|
||||
--correct for the player's height
|
||||
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
|
||||
|
||||
--correct for 6d facedir
|
||||
if placer_pos then
|
||||
local dir = {
|
||||
x = pos.x - placer_pos.x,
|
||||
y = pos.y - placer_pos.y,
|
||||
z = pos.z - placer_pos.z
|
||||
}
|
||||
local node = minetest.get_node(pos)
|
||||
node.param2 = minetest.dir_to_facedir(dir, true)
|
||||
minetest.set_node(pos, node)
|
||||
minetest.log("action", "real (6d) facedir: " .. node.param2)
|
||||
end
|
||||
|
||||
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
|
||||
end,
|
||||
after_dig_node = pipeworks.scan_for_tube_objects,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
})
|
||||
|
||||
function hacky_swap_node(pos,name)
|
||||
local node=minetest.env:get_node(pos)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local meta0=meta:to_table()
|
||||
node.name=name
|
||||
minetest.env:add_node(pos, node)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
meta:from_table(meta0)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,25 @@
|
|||
-- List of devices that should participate in the autoplace algorithm
|
||||
|
||||
pipes_devicelist = {
|
||||
local pipereceptor_on = nil
|
||||
local pipereceptor_off = nil
|
||||
|
||||
if mesecon then
|
||||
pipereceptor_on = {
|
||||
receptor = {
|
||||
state = mesecon.state.on,
|
||||
rules = pipeworks.mesecons_rules
|
||||
}
|
||||
}
|
||||
|
||||
pipereceptor_off = {
|
||||
receptor = {
|
||||
state = mesecon.state.off,
|
||||
rules = pipeworks.mesecons_rules
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
local pipes_devicelist = {
|
||||
"pump",
|
||||
"valve",
|
||||
"storage_tank_0",
|
||||
|
@ -16,51 +35,11 @@ pipes_devicelist = {
|
|||
"storage_tank_10"
|
||||
}
|
||||
|
||||
-- tables
|
||||
|
||||
pipe_pumpbody = {
|
||||
{ -7/16, -6/16, -7/16, 7/16, 5/16, 7/16 },
|
||||
{ -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 }
|
||||
}
|
||||
|
||||
pipe_valvebody = {
|
||||
{ -4/16, -4/16, -4/16, 4/16, 4/16, 4/16 }
|
||||
}
|
||||
|
||||
pipe_valvehandle_on = {
|
||||
{ -5/16, 4/16, -1/16, 0, 5/16, 1/16 }
|
||||
}
|
||||
|
||||
pipe_valvehandle_off = {
|
||||
{ -1/16, 4/16, -5/16, 1/16, 5/16, 0 }
|
||||
}
|
||||
|
||||
spigot_bottomstub = {
|
||||
{ -2/64, -16/64, -6/64, 2/64, 1/64, 6/64 }, -- pipe segment against -Y face
|
||||
{ -4/64, -16/64, -5/64, 4/64, 1/64, 5/64 },
|
||||
{ -5/64, -16/64, -4/64, 5/64, 1/64, 4/64 },
|
||||
{ -6/64, -16/64, -2/64, 6/64, 1/64, 2/64 },
|
||||
|
||||
{ -3/64, -16/64, -8/64, 3/64, -14/64, 8/64 }, -- (the flange for it)
|
||||
{ -5/64, -16/64, -7/64, 5/64, -14/64, 7/64 },
|
||||
{ -6/64, -16/64, -6/64, 6/64, -14/64, 6/64 },
|
||||
{ -7/64, -16/64, -5/64, 7/64, -14/64, 5/64 },
|
||||
{ -8/64, -16/64, -3/64, 8/64, -14/64, 3/64 }
|
||||
}
|
||||
|
||||
spigot_stream = {
|
||||
{ -3/64, -48/64, -5/64, 3/64, -16/64, 5/64 },
|
||||
{ -4/64, -48/64, -4/64, 4/64, -16/64, 4/64 },
|
||||
{ -5/64, -48/64, -3/64, 5/64, -16/64, 3/64 }
|
||||
}
|
||||
|
||||
entry_panel = {
|
||||
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
|
||||
}
|
||||
-- Now define the nodes.
|
||||
|
||||
local states = { "on", "off" }
|
||||
local dgroups = ""
|
||||
local pumpboxes = {}
|
||||
|
||||
for s in ipairs(states) do
|
||||
|
||||
|
@ -70,9 +49,10 @@ for s in ipairs(states) do
|
|||
dgroups = {snappy=3, pipe=1, not_in_creative_inventory=1}
|
||||
end
|
||||
|
||||
local pumpboxes = {}
|
||||
pipe_addbox(pumpboxes, pipe_pumpbody)
|
||||
pipe_addbox(pumpboxes, pipe_topstub)
|
||||
pumpboxes = {}
|
||||
|
||||
pipeworks.add_node_box(pumpboxes, pipeworks.pipe_pumpbody)
|
||||
pipeworks.add_node_box(pumpboxes, pipeworks.pipe_topstub)
|
||||
|
||||
minetest.register_node("pipeworks:pump_"..states[s], {
|
||||
description = "Pump/Intake Module",
|
||||
|
@ -98,33 +78,40 @@ for s in ipairs(states) do
|
|||
groups = dgroups,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
pipelike = 1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
drop = "pipeworks:pump_off"
|
||||
drop = "pipeworks:pump_off",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:pump_on", param2 = node.param2})
|
||||
end,
|
||||
action_off = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:pump_off", param2 = node.param2})
|
||||
end
|
||||
}},
|
||||
on_punch = function(pos, node, puncher)
|
||||
local fdir = minetest.get_node(pos).param2
|
||||
minetest.add_node(pos, { name = "pipeworks:pump_"..states[3-s], param2 = fdir })
|
||||
end
|
||||
})
|
||||
|
||||
local valveboxes = {}
|
||||
pipe_addbox(valveboxes, pipe_leftstub)
|
||||
pipe_addbox(valveboxes, pipe_valvebody)
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_leftstub)
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvebody)
|
||||
if states[s] == "off" then
|
||||
pipe_addbox(valveboxes, pipe_valvehandle_off)
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvehandle_off)
|
||||
else
|
||||
pipe_addbox(valveboxes, pipe_valvehandle_on)
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvehandle_on)
|
||||
end
|
||||
pipe_addbox(valveboxes, pipe_rightstub)
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_rightstub)
|
||||
local tilex = "pipeworks_valvebody_ends.png"
|
||||
local tilez = "pipeworks_valvebody_sides.png"
|
||||
|
||||
minetest.register_node("pipeworks:valve_"..states[s], {
|
||||
minetest.register_node("pipeworks:valve_"..states[s].."_empty", {
|
||||
description = "Valve",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
|
@ -135,6 +122,7 @@ for s in ipairs(states) do
|
|||
tilez,
|
||||
tilez,
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
selection_box = {
|
||||
|
@ -148,22 +136,80 @@ for s in ipairs(states) do
|
|||
groups = dgroups,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
pipelike = 1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
drop = "pipeworks:valve_off",
|
||||
pipelike=1,
|
||||
drop = "pipeworks:valve_off_empty",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
||||
end,
|
||||
action_off = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
||||
end
|
||||
}},
|
||||
on_punch = function(pos, node, puncher)
|
||||
local fdir = minetest.get_node(pos).param2
|
||||
minetest.add_node(pos, { name = "pipeworks:valve_"..states[3-s].."_empty", param2 = fdir })
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local valveboxes = {}
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_leftstub)
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvebody)
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_rightstub)
|
||||
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvehandle_on)
|
||||
|
||||
minetest.register_node("pipeworks:valve_on_loaded", {
|
||||
description = "Valve",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"pipeworks_valvebody_top_on.png",
|
||||
"pipeworks_valvebody_bottom.png",
|
||||
"pipeworks_valvebody_ends.png",
|
||||
"pipeworks_valvebody_ends.png",
|
||||
"pipeworks_valvebody_sides.png",
|
||||
"pipeworks_valvebody_sides.png",
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -8/16, -4/16, -5/16, 8/16, 5/16, 5/16 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = valveboxes
|
||||
},
|
||||
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
drop = "pipeworks:valve_off_empty",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
||||
end,
|
||||
action_off = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
||||
end
|
||||
}},
|
||||
on_punch = function(pos, node, puncher)
|
||||
local fdir = minetest.get_node(pos).param2
|
||||
minetest.add_node(pos, { name = "pipeworks:valve_off_empty", param2 = fdir })
|
||||
end
|
||||
})
|
||||
|
||||
-- grating
|
||||
|
||||
minetest.register_node("pipeworks:grating", {
|
||||
|
@ -176,62 +222,54 @@ minetest.register_node("pipeworks:grating", {
|
|||
"pipeworks_grating_sides.png",
|
||||
"pipeworks_grating_sides.png"
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
groups = {snappy=3, pipe=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
end,
|
||||
pipelike=1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
-- outlet spigot
|
||||
|
||||
local spigotboxes = {}
|
||||
pipe_addbox(spigotboxes, pipe_backstub)
|
||||
pipe_addbox(spigotboxes, spigot_bottomstub)
|
||||
pipe_addbox(spigotboxes, pipe_bendsphere)
|
||||
pipeworks.add_node_box(spigotboxes, pipeworks.pipe_backstub)
|
||||
pipeworks.add_node_box(spigotboxes, pipeworks.spigot_bottomstub)
|
||||
pipeworks.add_node_box(spigotboxes, pipeworks.pipe_bendsphere)
|
||||
|
||||
local spigotboxes_pouring = {}
|
||||
pipe_addbox(spigotboxes_pouring, spigot_stream)
|
||||
pipe_addbox(spigotboxes_pouring, pipe_backstub)
|
||||
pipe_addbox(spigotboxes_pouring, spigot_bottomstub)
|
||||
pipe_addbox(spigotboxes_pouring, pipe_bendsphere)
|
||||
pipeworks.add_node_box(spigotboxes_pouring, pipeworks.spigot_stream)
|
||||
pipeworks.add_node_box(spigotboxes_pouring, pipeworks.pipe_backstub)
|
||||
pipeworks.add_node_box(spigotboxes_pouring, pipeworks.spigot_bottomstub)
|
||||
pipeworks.add_node_box(spigotboxes_pouring, pipeworks.pipe_bendsphere)
|
||||
|
||||
minetest.register_node("pipeworks:spigot", {
|
||||
description = "Spigot outlet",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"pipeworks_spigot_sides.png",
|
||||
"pipeworks_spigot_sides.png",
|
||||
"pipeworks_pipe_end_empty.png",
|
||||
"pipeworks_spigot_sides.png",
|
||||
"pipeworks_spigot_sides.png",
|
||||
"pipeworks_pipe_end_empty.png",
|
||||
"pipeworks_spigot_sides.png"
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=3, pipe=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
pipelike=1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
|
@ -248,27 +286,51 @@ minetest.register_node("pipeworks:spigot_pouring", {
|
|||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"pipeworks_spigot_sides.png",
|
||||
"pipeworks_spigot_sides.png",
|
||||
"default_water.png^pipeworks_spigot_sides2.png",
|
||||
"default_water.png^pipeworks_spigot_sides2.png",
|
||||
"default_water.png^pipeworks_spigot_sides2.png",
|
||||
"default_water.png^pipeworks_spigot_sides2.png"
|
||||
"default_water.png^pipeworks_spigot_bottom2.png",
|
||||
{ name = "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w=16,
|
||||
aspect_h=16,
|
||||
length=0.8
|
||||
}
|
||||
},
|
||||
{ name = "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w=16,
|
||||
aspect_h=16,
|
||||
length=0.8
|
||||
}
|
||||
},
|
||||
{ name = "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w=16,
|
||||
aspect_h=16,
|
||||
length=0.8
|
||||
}
|
||||
},
|
||||
{ name = "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w=16,
|
||||
aspect_h=16,
|
||||
length=0.8
|
||||
}
|
||||
},
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=3, pipe=1},
|
||||
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
pipelike=1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
|
@ -281,16 +343,15 @@ minetest.register_node("pipeworks:spigot_pouring", {
|
|||
drop = "pipeworks:spigot",
|
||||
})
|
||||
|
||||
|
||||
-- sealed pipe entry/exit (decorative horizontal pipe passing through a metal
|
||||
-- sealed pipe entry/exit (horizontal pipe passing through a metal
|
||||
-- wall, for use in places where walls should look like they're airtight)
|
||||
|
||||
local airtightboxes = {}
|
||||
pipe_addbox(airtightboxes, pipe_frontstub)
|
||||
pipe_addbox(airtightboxes, pipe_backstub)
|
||||
pipe_addbox(airtightboxes, entry_panel)
|
||||
local airtightboxes = {}
|
||||
pipeworks.add_node_box(airtightboxes, pipeworks.pipe_frontstub)
|
||||
pipeworks.add_node_box(airtightboxes, pipeworks.pipe_backstub)
|
||||
pipeworks.add_node_box(airtightboxes, pipeworks.entry_panel)
|
||||
|
||||
minetest.register_node("pipeworks:entry_panel", {
|
||||
minetest.register_node("pipeworks:entry_panel_empty", {
|
||||
description = "Airtight Pipe entry/exit",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
|
@ -307,31 +368,210 @@ minetest.register_node("pipeworks:entry_panel", {
|
|||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
end,
|
||||
pipelike=1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = airtightboxes,
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -2/16, -2/16, -8/16, 2/16, 2/16, 8/16 },
|
||||
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
|
||||
}
|
||||
},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if not pipeworks.node_is_owned(pointed_thing.under, placer)
|
||||
and not pipeworks.node_is_owned(pointed_thing.above, placer) then
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
|
||||
if not minetest.registered_nodes[node.name]
|
||||
or not minetest.registered_nodes[node.name].on_rightclick then
|
||||
local pitch = placer:get_look_pitch()
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||
local undernode = minetest.get_node(under)
|
||||
local abovenode = minetest.get_node(above)
|
||||
local uname = undernode.name
|
||||
local aname = abovenode.name
|
||||
local isabove = (above.x == under.x) and (above.z == under.z) and (pitch > 0)
|
||||
local pos1 = above
|
||||
|
||||
if above.x == under.x
|
||||
and above.z == under.z
|
||||
and ( string.find(uname, "pipeworks:pipe_")
|
||||
or string.find(uname, "pipeworks:storage_")
|
||||
or string.find(uname, "pipeworks:expansion_")
|
||||
or ( string.find(uname, "pipeworks:grating") and not isabove )
|
||||
or ( string.find(uname, "pipeworks:pump_") and not isabove )
|
||||
or ( string.find(uname, "pipeworks:entry_panel")
|
||||
and undernode.param2 == 13 )
|
||||
)
|
||||
then
|
||||
fdir = 13
|
||||
end
|
||||
|
||||
if minetest.registered_nodes[uname]["buildable_to"] then
|
||||
pos1 = under
|
||||
end
|
||||
|
||||
if not minetest.registered_nodes[minetest.get_node(pos1).name]["buildable_to"] then return end
|
||||
|
||||
minetest.add_node(pos1, {name = "pipeworks:entry_panel_empty", param2 = fdir })
|
||||
pipeworks.scan_for_pipe_objects(pos1)
|
||||
|
||||
if not pipeworks.expect_infinite_stacks then
|
||||
itemstack:take_item()
|
||||
end
|
||||
|
||||
else
|
||||
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("pipeworks:entry_panel_loaded", {
|
||||
description = "Airtight Pipe entry/exit",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_pipe_end_empty.png",
|
||||
"pipeworks_pipe_end_empty.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = airtightboxes,
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -2/16, -2/16, -8/16, 2/16, 2/16, 8/16 },
|
||||
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
|
||||
}
|
||||
},
|
||||
drop = "pipeworks:entry_panel_empty"
|
||||
})
|
||||
|
||||
local sensorboxes = {}
|
||||
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_leftstub)
|
||||
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_sensorbody)
|
||||
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_rightstub)
|
||||
|
||||
minetest.register_node("pipeworks:flow_sensor_empty", {
|
||||
description = "Flow Sensor",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_windowed_empty.png",
|
||||
"pipeworks_windowed_empty.png"
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=3, pipe=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
if mesecon then
|
||||
mesecon:receptor_off(pos, rules)
|
||||
end
|
||||
end,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = sensorboxes,
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -8/16, -2/16, -2/16, 8/16, 2/16, 2/16 },
|
||||
}
|
||||
},
|
||||
mesecons = pipereceptor_off
|
||||
})
|
||||
|
||||
minetest.register_node("pipeworks:flow_sensor_loaded", {
|
||||
description = "Flow sensor (on)",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_sensor_sides_on.png",
|
||||
"pipeworks_sensor_sides_on.png"
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
if mesecon then
|
||||
mesecon:receptor_on(pos, rules)
|
||||
end
|
||||
end,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = sensorboxes,
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -8/16, -2/16, -2/16, 8/16, 2/16, 2/16 },
|
||||
}
|
||||
},
|
||||
drop = "pipeworks:flow_sensor_empty",
|
||||
mesecons = pipereceptor_on
|
||||
})
|
||||
|
||||
-- tanks
|
||||
|
||||
for fill = 0, 10 do
|
||||
if fill == 0 then
|
||||
filldesc="empty"
|
||||
sgroups = {snappy=3, pipe=1, tankfill=fill+1}
|
||||
else
|
||||
local filldesc="empty"
|
||||
local sgroups = {snappy=3, pipe=1, tankfill=fill+1}
|
||||
local image = nil
|
||||
|
||||
if fill ~= 0 then
|
||||
filldesc=fill.."0% full"
|
||||
sgroups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1}
|
||||
image = "pipeworks_storage_tank_fittings.png"
|
||||
end
|
||||
|
||||
minetest.register_node("pipeworks:expansion_tank_"..fill, {
|
||||
|
@ -342,8 +582,9 @@ for fill = 0, 10 do
|
|||
"pipeworks_storage_tank_back.png",
|
||||
"pipeworks_storage_tank_back.png",
|
||||
"pipeworks_storage_tank_back.png",
|
||||
pipeworks_liquid_texture.."^pipeworks_storage_tank_front_"..fill..".png"
|
||||
pipeworks.liquid_texture.."^pipeworks_storage_tank_front_"..fill..".png"
|
||||
},
|
||||
inventory_image = image,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1},
|
||||
|
@ -351,16 +592,11 @@ for fill = 0, 10 do
|
|||
walkable = true,
|
||||
drop = "pipeworks:storage_tank_"..fill,
|
||||
after_place_node = function(pos)
|
||||
pipe_look_for_stackable_tanks(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.look_for_stackable_tanks(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
end,
|
||||
pipelike=0,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",0)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -372,94 +608,94 @@ for fill = 0, 10 do
|
|||
"pipeworks_storage_tank_back.png",
|
||||
"pipeworks_storage_tank_back.png",
|
||||
"pipeworks_storage_tank_back.png",
|
||||
pipeworks_liquid_texture.."^pipeworks_storage_tank_front_"..fill..".png"
|
||||
pipeworks.liquid_texture.."^pipeworks_storage_tank_front_"..fill..".png"
|
||||
},
|
||||
inventory_image = image,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = sgroups,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipe_look_for_stackable_tanks(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
pipeworks.look_for_stackable_tanks(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
end,
|
||||
pipelike=1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
-- various actions
|
||||
-- fountainhead
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
if node.name=="pipeworks:valve_on" then
|
||||
fdir = minetest.env:get_node(pos).param2
|
||||
minetest.env:add_node(pos, { name = "pipeworks:valve_off", param2 = fdir })
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",0)
|
||||
end
|
||||
end)
|
||||
minetest.register_node("pipeworks:fountainhead", {
|
||||
description = "Fountainhead",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"pipeworks_fountainhead_top.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
groups = {snappy=3, pipe=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
if mesecon then
|
||||
mesecon:receptor_on(pos, rules)
|
||||
end
|
||||
end,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = pipeworks.fountainhead_model ,
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
if node.name=="pipeworks:valve_off" then
|
||||
fdir = minetest.env:get_node(pos).param2
|
||||
minetest.env:add_node(pos, { name = "pipeworks:valve_on", param2 = fdir })
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
end
|
||||
end)
|
||||
minetest.register_node("pipeworks:fountainhead_pouring", {
|
||||
description = "Fountainhead",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"pipeworks_fountainhead_top.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
if mesecon then
|
||||
mesecon:receptor_on(pos, rules)
|
||||
end
|
||||
end,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = pipeworks.fountainhead_model,
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 },
|
||||
},
|
||||
drop = "pipeworks:fountainhead"
|
||||
})
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
if node.name=="pipeworks:pump_on" then
|
||||
fdir = minetest.env:get_node(pos).param2
|
||||
minetest.env:add_node(pos, { name = "pipeworks:pump_off", param2 = fdir })
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
if node.name=="pipeworks:pump_off" then
|
||||
fdir = minetest.env:get_node(pos).param2
|
||||
minetest.env:add_node(pos, { name = "pipeworks:pump_on", param2 = fdir })
|
||||
end
|
||||
end)
|
||||
|
||||
-- backwards compatibility
|
||||
|
||||
minetest.register_alias("pipeworks:intake", "pipeworks:grating")
|
||||
minetest.register_alias("pipeworks:outlet", "pipeworks:grating")
|
||||
minetest.register_alias("pipeworks:pump_off_x", "pipeworks:pump_off")
|
||||
minetest.register_alias("pipeworks:pump_off_z", "pipeworks:pump_off")
|
||||
minetest.register_alias("pipeworks:pump_on_x", "pipeworks:pump_on")
|
||||
minetest.register_alias("pipeworks:pump_on_z", "pipeworks:pump_on")
|
||||
minetest.register_alias("pipeworks:valve_off_x", "pipeworks:valve_off")
|
||||
minetest.register_alias("pipeworks:valve_off_z", "pipeworks:valve_off")
|
||||
minetest.register_alias("pipeworks:valve_on_x", "pipeworks:valve_on")
|
||||
minetest.register_alias("pipeworks:valve_on_z", "pipeworks:valve_on")
|
||||
minetest.register_alias("pipeworks:storage_tank_0_x", "pipeworks:storage_tank_0")
|
||||
minetest.register_alias("pipeworks:storage_tank_0_z", "pipeworks:storage_tank_0")
|
||||
minetest.register_alias("pipeworks:storage_tank_1_x", "pipeworks:storage_tank_1")
|
||||
minetest.register_alias("pipeworks:storage_tank_1_z", "pipeworks:storage_tank_1")
|
||||
minetest.register_alias("pipeworks:storage_tank_2_x", "pipeworks:storage_tank_2")
|
||||
minetest.register_alias("pipeworks:storage_tank_2_z", "pipeworks:storage_tank_2")
|
||||
minetest.register_alias("pipeworks:storage_tank_3_x", "pipeworks:storage_tank_3")
|
||||
minetest.register_alias("pipeworks:storage_tank_3_z", "pipeworks:storage_tank_3")
|
||||
minetest.register_alias("pipeworks:storage_tank_4_x", "pipeworks:storage_tank_4")
|
||||
minetest.register_alias("pipeworks:storage_tank_4_z", "pipeworks:storage_tank_4")
|
||||
minetest.register_alias("pipeworks:storage_tank_5_x", "pipeworks:storage_tank_5")
|
||||
minetest.register_alias("pipeworks:storage_tank_5_z", "pipeworks:storage_tank_5")
|
||||
minetest.register_alias("pipeworks:storage_tank_6_x", "pipeworks:storage_tank_6")
|
||||
minetest.register_alias("pipeworks:storage_tank_6_z", "pipeworks:storage_tank_6")
|
||||
minetest.register_alias("pipeworks:storage_tank_7_x", "pipeworks:storage_tank_7")
|
||||
minetest.register_alias("pipeworks:storage_tank_7_z", "pipeworks:storage_tank_7")
|
||||
minetest.register_alias("pipeworks:storage_tank_8_x", "pipeworks:storage_tank_8")
|
||||
minetest.register_alias("pipeworks:storage_tank_8_z", "pipeworks:storage_tank_8")
|
||||
minetest.register_alias("pipeworks:storage_tank_9_x", "pipeworks:storage_tank_9")
|
||||
minetest.register_alias("pipeworks:storage_tank_9_z", "pipeworks:storage_tank_9")
|
||||
minetest.register_alias("pipeworks:storage_tank_10_x", "pipeworks:storage_tank_10")
|
||||
minetest.register_alias("pipeworks:storage_tank_10_z", "pipeworks:storage_tank_10")
|
||||
minetest.register_alias("pipeworks:valve_off_loaded", "pipeworks:valve_off_empty")
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
-- This file provides the actual flow and pathfinding logic that makes water
|
||||
-- move through the pipes.
|
||||
--
|
||||
-- Contributed by mauvebic, 2013-01-03, with tweaks by Vanessa Ezekowitz
|
||||
-- Contributed by mauvebic, 2013-01-03, rewritten a bit by Vanessa Ezekowitz
|
||||
--
|
||||
|
||||
local check4liquids = function(pos)
|
||||
local finitewater = minetest.setting_getbool("liquid_finite")
|
||||
|
||||
pipeworks.check_for_liquids = function(pos)
|
||||
local coords = {
|
||||
{x=pos.x,y=pos.y-1,z=pos.z},
|
||||
{x=pos.x,y=pos.y+1,z=pos.z},
|
||||
|
@ -13,13 +15,16 @@ local check4liquids = function(pos)
|
|||
{x=pos.x,y=pos.y,z=pos.z-1},
|
||||
{x=pos.x,y=pos.y,z=pos.z+1}, }
|
||||
for i =1,6 do
|
||||
local name = minetest.env:get_node(coords[i]).name
|
||||
if string.find(name,'water') then return true end
|
||||
local name = minetest.get_node(coords[i]).name
|
||||
if name and string.find(name,"water") then
|
||||
if finitewater then minetest.remove_node(coords[i]) end
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local check4inflows = function(pos,node)
|
||||
pipeworks.check_for_inflows = function(pos,node)
|
||||
local coords = {
|
||||
{x=pos.x,y=pos.y-1,z=pos.z},
|
||||
{x=pos.x,y=pos.y+1,z=pos.z},
|
||||
|
@ -31,83 +36,86 @@ local check4inflows = function(pos,node)
|
|||
local source = false
|
||||
for i =1,6 do
|
||||
if newnode then break end
|
||||
local name = minetest.env:get_node(coords[i]).name
|
||||
if (name == 'pipeworks:pump_on' and check4liquids(coords[i])) or string.find(name,'_loaded') then
|
||||
if string.find(name,'_loaded') then
|
||||
local source = minetest.env:get_meta(coords[i]):get_string('source')
|
||||
local name = minetest.get_node(coords[i]).name
|
||||
if name and (name == "pipeworks:pump_on" and pipeworks.check_for_liquids(coords[i])) or string.find(name,"_loaded") then
|
||||
if string.find(name,"_loaded") then
|
||||
source = minetest.get_meta(coords[i]):get_string("source")
|
||||
if source == minetest.pos_to_string(pos) then break end
|
||||
end
|
||||
newnode = string.gsub(node.name,'empty','loaded')
|
||||
newnode = string.gsub(node.name,"empty","loaded")
|
||||
source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
|
||||
if newnode ~= nil then dbg(newnode) end
|
||||
end
|
||||
end
|
||||
if newnode then
|
||||
dbg(newnode..' to replace '..node.name)
|
||||
minetest.env:add_node(pos,{name=newnode})
|
||||
minetest.env:get_meta(pos):set_string('source',minetest.pos_to_string(source))
|
||||
minetest.add_node(pos,{name=newnode, param2 = node.param2})
|
||||
minetest.get_meta(pos):set_string("source",minetest.pos_to_string(source))
|
||||
end
|
||||
end
|
||||
|
||||
local checksources = function(pos,node)
|
||||
local sourcepos = minetest.string_to_pos(minetest.env:get_meta(pos):get_string('source'))
|
||||
local source = minetest.env:get_node(sourcepos).name
|
||||
pipeworks.check_sources = function(pos,node)
|
||||
local sourcepos = minetest.string_to_pos(minetest.get_meta(pos):get_string("source"))
|
||||
if not sourcepos then return end
|
||||
local source = minetest.get_node(sourcepos).name
|
||||
local newnode = false
|
||||
if not ((source == 'pipeworks:pump_on' and check4liquids(sourcepos)) or string.find(source,'_loaded') or source == 'ignore' ) then
|
||||
newnode = string.gsub(node.name,'loaded','empty')
|
||||
if source and not ((source == "pipeworks:pump_on" and pipeworks.check_for_liquids(sourcepos)) or string.find(source,"_loaded") or source == "ignore" ) then
|
||||
newnode = string.gsub(node.name,"loaded","empty")
|
||||
end
|
||||
|
||||
if newnode then dbg(newnode..' to replace '..node.name) end
|
||||
if newnode then
|
||||
minetest.env:add_node(pos,{name=newnode})
|
||||
minetest.env:get_meta(pos):set_string('source','')
|
||||
minetest.add_node(pos,{name=newnode, param2 = node.param2})
|
||||
minetest.get_meta(pos):set_string("source","")
|
||||
end
|
||||
end
|
||||
|
||||
local update_outlet = function(pos)
|
||||
local top = minetest.env:get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
|
||||
if string.find(top,'_loaded') then
|
||||
minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'})
|
||||
elseif minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then
|
||||
minetest.env:remove_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||
pipeworks.spigot_check = function(pos, node)
|
||||
local belowname = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
|
||||
if belowname and (belowname == "air" or belowname == "default:water_flowing" or belowname == "default:water_source") then
|
||||
local spigotname = minetest.get_node(pos).name
|
||||
local fdir=node.param2
|
||||
local check = {
|
||||
{x=pos.x,y=pos.y,z=pos.z+1},
|
||||
{x=pos.x+1,y=pos.y,z=pos.z},
|
||||
{x=pos.x,y=pos.y,z=pos.z-1},
|
||||
{x=pos.x-1,y=pos.y,z=pos.z}
|
||||
}
|
||||
local near_node = minetest.get_node(check[fdir+1])
|
||||
if near_node and string.find(near_node.name, "_loaded") then
|
||||
if spigotname and spigotname == "pipeworks:spigot" then
|
||||
minetest.add_node(pos,{name = "pipeworks:spigot_pouring", param2 = fdir})
|
||||
if finitewater or belowname ~= "default:water_source" then
|
||||
minetest.add_node({x=pos.x,y=pos.y-1,z=pos.z},{name = "default:water_source"})
|
||||
end
|
||||
end
|
||||
else
|
||||
if spigotname == "pipeworks:spigot_pouring" then
|
||||
minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name = "pipeworks:spigot", param2 = fdir})
|
||||
if belowname == "default:water_source" and not finitewater then
|
||||
minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local spigot_check = function(pos,node)
|
||||
local fdir=node.param2
|
||||
local check = {{x=pos.x,y=pos.y,z=pos.z+1},{x=pos.x+1,y=pos.y,z=pos.z},{x=pos.x,y=pos.y,z=pos.z-1},{x=pos.x-1,y=pos.y,z=pos.z} }
|
||||
dbg(fdir..' checking '..minetest.pos_to_string(check[fdir+1])..' for spigot at '..minetest.pos_to_string(pos))
|
||||
local top = minetest.env:get_node(check[fdir+1]).name
|
||||
dbg('found '..top)
|
||||
if string.find(top,'_loaded') then
|
||||
minetest.env:add_node({x=pos.x,y=pos.y,z=pos.z},{name='pipeworks:spigot_pouring', param2 = fdir})
|
||||
minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'})
|
||||
elseif minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then
|
||||
minetest.env:add_node({x=pos.x,y=pos.y,z=pos.z},{name='pipeworks:spigot', param2 = fdir})
|
||||
minetest.env:remove_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||
pipeworks.fountainhead_check = function(pos, node)
|
||||
local abovename = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
|
||||
if abovename and (abovename == "air" or abovename == "default:water_flowing" or abovename == "default:water_source") then
|
||||
local fountainhead_name = minetest.get_node(pos).name
|
||||
local near_node = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||
if near_node and string.find(near_node.name, "_loaded") then
|
||||
if fountainhead_name and fountainhead_name == "pipeworks:fountainhead" then
|
||||
minetest.add_node(pos,{name = "pipeworks:fountainhead_pouring"})
|
||||
if finitewater or abovename ~= "default:water_source" then
|
||||
minetest.add_node({x=pos.x,y=pos.y+1,z=pos.z},{name = "default:water_source"})
|
||||
end
|
||||
end
|
||||
else
|
||||
if fountainhead_name == "pipeworks:fountainhead_pouring" then
|
||||
minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name = "pipeworks:fountainhead"})
|
||||
if abovename == "default:water_source" and not finitewater then
|
||||
minetest.remove_node({x=pos.x,y=pos.y+1,z=pos.z})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = pipes_empty_nodenames,
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider) check4inflows(pos,node) end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = pipes_full_nodenames,
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider) checksources(pos,node) end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {'pipeworks:outlet','pipeworks:spigot','pipeworks:spigot_pouring'},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if node.name == 'pipeworks:outlet' then update_outlet(pos)
|
||||
elseif node.name == 'pipeworks:spigot' or node.name == 'pipeworks:spigot_pouring' then spigot_check(pos,node) end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,127 +1,48 @@
|
|||
-- Pipeworks mod by Vanessa Ezekowitz - 2012-08-05
|
||||
-- Pipeworks mod by Vanessa Ezekowitz - 2013-07-13
|
||||
--
|
||||
-- Entirely my own code. This mod supplies various shapes of pipes
|
||||
-- and devices that they can connect to such as pumps, valves, etc.
|
||||
-- All pipes autoconnect as you lay them out, and devices will auto-
|
||||
-- connect to them.
|
||||
-- This mod supplies various steel pipes and plastic pneumatic tubes
|
||||
-- and devices that they can connect to.
|
||||
--
|
||||
-- License: WTFPL
|
||||
--
|
||||
|
||||
-- Un-comment the following dofile line to re-enable the old pipe nodes.
|
||||
-- dofile(minetest.get_modpath("pipeworks").."/oldpipes.lua")
|
||||
--
|
||||
pipeworks = {}
|
||||
|
||||
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
|
||||
local DEBUG = false
|
||||
|
||||
pipeworks_liquid_texture = "default_water.png"
|
||||
pipeworks.worldpath = minetest.get_worldpath()
|
||||
pipeworks.modpath = minetest.get_modpath("pipeworks")
|
||||
|
||||
pipe_leftstub = {
|
||||
{ -32/64, -2/64, -6/64, 1/64, 2/64, 6/64 }, -- pipe segment against -X face
|
||||
{ -32/64, -4/64, -5/64, 1/64, 4/64, 5/64 },
|
||||
{ -32/64, -5/64, -4/64, 1/64, 5/64, 4/64 },
|
||||
{ -32/64, -6/64, -2/64, 1/64, 6/64, 2/64 },
|
||||
dofile(pipeworks.modpath.."/default_settings.txt")
|
||||
|
||||
{ -32/64, -3/64, -8/64, -30/64, 3/64, 8/64 }, -- (the flange for it)
|
||||
{ -32/64, -5/64, -7/64, -30/64, 5/64, 7/64 },
|
||||
{ -32/64, -6/64, -6/64, -30/64, 6/64, 6/64 },
|
||||
{ -32/64, -7/64, -5/64, -30/64, 7/64, 5/64 },
|
||||
{ -32/64, -8/64, -3/64, -30/64, 8/64, 3/64 }
|
||||
}
|
||||
|
||||
pipe_rightstub = {
|
||||
{ -1/64, -2/64, -6/64, 32/64, 2/64, 6/64 }, -- pipe segment against +X face
|
||||
{ -1/64, -4/64, -5/64, 32/64, 4/64, 5/64 },
|
||||
{ -1/64, -5/64, -4/64, 32/64, 5/64, 4/64 },
|
||||
{ -1/64, -6/64, -2/64, 32/64, 6/64, 2/64 },
|
||||
|
||||
{ 30/64, -3/64, -8/64, 32/64, 3/64, 8/64 }, -- (the flange for it)
|
||||
{ 30/64, -5/64, -7/64, 32/64, 5/64, 7/64 },
|
||||
{ 30/64, -6/64, -6/64, 32/64, 6/64, 6/64 },
|
||||
{ 30/64, -7/64, -5/64, 32/64, 7/64, 5/64 },
|
||||
{ 30/64, -8/64, -3/64, 32/64, 8/64, 3/64 }
|
||||
}
|
||||
|
||||
pipe_bottomstub = {
|
||||
{ -2/64, -32/64, -6/64, 2/64, 1/64, 6/64 }, -- pipe segment against -Y face
|
||||
{ -4/64, -32/64, -5/64, 4/64, 1/64, 5/64 },
|
||||
{ -5/64, -32/64, -4/64, 5/64, 1/64, 4/64 },
|
||||
{ -6/64, -32/64, -2/64, 6/64, 1/64, 2/64 },
|
||||
|
||||
{ -3/64, -32/64, -8/64, 3/64, -30/64, 8/64 }, -- (the flange for it)
|
||||
{ -5/64, -32/64, -7/64, 5/64, -30/64, 7/64 },
|
||||
{ -6/64, -32/64, -6/64, 6/64, -30/64, 6/64 },
|
||||
{ -7/64, -32/64, -5/64, 7/64, -30/64, 5/64 },
|
||||
{ -8/64, -32/64, -3/64, 8/64, -30/64, 3/64 }
|
||||
}
|
||||
|
||||
|
||||
pipe_topstub = {
|
||||
{ -2/64, -1/64, -6/64, 2/64, 32/64, 6/64 }, -- pipe segment against +Y face
|
||||
{ -4/64, -1/64, -5/64, 4/64, 32/64, 5/64 },
|
||||
{ -5/64, -1/64, -4/64, 5/64, 32/64, 4/64 },
|
||||
{ -6/64, -1/64, -2/64, 6/64, 32/64, 2/64 },
|
||||
|
||||
{ -3/64, 30/64, -8/64, 3/64, 32/64, 8/64 }, -- (the flange for it)
|
||||
{ -5/64, 30/64, -7/64, 5/64, 32/64, 7/64 },
|
||||
{ -6/64, 30/64, -6/64, 6/64, 32/64, 6/64 },
|
||||
{ -7/64, 30/64, -5/64, 7/64, 32/64, 5/64 },
|
||||
{ -8/64, 30/64, -3/64, 8/64, 32/64, 3/64 }
|
||||
}
|
||||
|
||||
pipe_frontstub = {
|
||||
{ -6/64, -2/64, -32/64, 6/64, 2/64, 1/64 }, -- pipe segment against -Z face
|
||||
{ -5/64, -4/64, -32/64, 5/64, 4/64, 1/64 },
|
||||
{ -4/64, -5/64, -32/64, 4/64, 5/64, 1/64 },
|
||||
{ -2/64, -6/64, -32/64, 2/64, 6/64, 1/64 },
|
||||
|
||||
{ -8/64, -3/64, -32/64, 8/64, 3/64, -30/64 }, -- (the flange for it)
|
||||
{ -7/64, -5/64, -32/64, 7/64, 5/64, -30/64 },
|
||||
{ -6/64, -6/64, -32/64, 6/64, 6/64, -30/64 },
|
||||
{ -5/64, -7/64, -32/64, 5/64, 7/64, -30/64 },
|
||||
{ -3/64, -8/64, -32/64, 3/64, 8/64, -30/64 }
|
||||
}
|
||||
|
||||
pipe_backstub = {
|
||||
{ -6/64, -2/64, -1/64, 6/64, 2/64, 32/64 }, -- pipe segment against -Z face
|
||||
{ -5/64, -4/64, -1/64, 5/64, 4/64, 32/64 },
|
||||
{ -4/64, -5/64, -1/64, 4/64, 5/64, 32/64 },
|
||||
{ -2/64, -6/64, -1/64, 2/64, 6/64, 32/64 },
|
||||
|
||||
{ -8/64, -3/64, 30/64, 8/64, 3/64, 32/64 }, -- (the flange for it)
|
||||
{ -7/64, -5/64, 30/64, 7/64, 5/64, 32/64 },
|
||||
{ -6/64, -6/64, 30/64, 6/64, 6/64, 32/64 },
|
||||
{ -5/64, -7/64, 30/64, 5/64, 7/64, 32/64 },
|
||||
{ -3/64, -8/64, 30/64, 3/64, 8/64, 32/64 }
|
||||
}
|
||||
|
||||
pipe_selectboxes = {
|
||||
{ -32/64, -8/64, -8/64, 8/64, 8/64, 8/64 },
|
||||
{ -8/64 , -8/64, -8/64, 32/64, 8/64, 8/64 },
|
||||
{ -8/64 , -32/64, -8/64, 8/64, 8/64, 8/64 },
|
||||
{ -8/64 , -8/64, -8/64, 8/64, 32/64, 8/64 },
|
||||
{ -8/64 , -8/64, -32/64, 8/64, 8/64, 8/64 },
|
||||
{ -8/64 , -8/64, -8/64, 8/64, 8/64, 32/64 }
|
||||
}
|
||||
|
||||
pipe_bendsphere = {
|
||||
{ -4/64, -4/64, -4/64, 4/64, 4/64, 4/64 },
|
||||
{ -5/64, -3/64, -3/64, 5/64, 3/64, 3/64 },
|
||||
{ -3/64, -5/64, -3/64, 3/64, 5/64, 3/64 },
|
||||
{ -3/64, -3/64, -5/64, 3/64, 3/64, 5/64 }
|
||||
}
|
||||
|
||||
-- Functions
|
||||
|
||||
dbg = function(s)
|
||||
if DEBUG then
|
||||
print('[PIPEWORKS] ' .. s)
|
||||
end
|
||||
-- Read the external config file if it exists.
|
||||
if io.open(pipeworks.worldpath.."/pipeworks_settings.txt","r") then
|
||||
dofile(pipeworks.worldpath.."/pipeworks_settings.txt")
|
||||
io.close()
|
||||
end
|
||||
|
||||
function pipes_fix_image_names(table, replacement)
|
||||
outtable={}
|
||||
-- Random variables
|
||||
|
||||
pipeworks.expect_infinite_stacks = true
|
||||
if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
|
||||
pipeworks.expect_infinite_stacks = false
|
||||
end
|
||||
|
||||
pipeworks.meseadjlist={{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}}
|
||||
|
||||
pipeworks.rules_all = {{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=1},{x=0, y=1, z=-1},{x=1, y=1, z=0},{x=-1, y=1, z=0},
|
||||
{x=0, y=-1, z=1},{x=0, y=-1, z=-1},{x=1, y=-1, z=0},{x=-1, y=-1, z=0},
|
||||
{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.liquid_texture = "default_water.png"
|
||||
|
||||
-- Helper functions
|
||||
|
||||
function pipeworks.fix_image_names(table, replacement)
|
||||
local outtable={}
|
||||
for i in ipairs(table) do
|
||||
outtable[i]=string.gsub(table[i], "_XXXXX", replacement)
|
||||
end
|
||||
|
@ -129,206 +50,79 @@ function pipes_fix_image_names(table, replacement)
|
|||
return outtable
|
||||
end
|
||||
|
||||
function pipe_addbox(t, b)
|
||||
function pipeworks.add_node_box(t, b)
|
||||
for i in ipairs(b)
|
||||
do table.insert(t, b[i])
|
||||
end
|
||||
end
|
||||
|
||||
-- now define the nodes!
|
||||
|
||||
pipes_empty_nodenames = {}
|
||||
pipes_full_nodenames = {}
|
||||
|
||||
for xm = 0, 1 do
|
||||
for xp = 0, 1 do
|
||||
for ym = 0, 1 do
|
||||
for yp = 0, 1 do
|
||||
for zm = 0, 1 do
|
||||
for zp = 0, 1 do
|
||||
local outboxes = {}
|
||||
local outsel = {}
|
||||
local outimgs = {}
|
||||
|
||||
if yp==1 then
|
||||
pipe_addbox(outboxes, pipe_topstub)
|
||||
table.insert(outsel, pipe_selectboxes[4])
|
||||
table.insert(outimgs, "pipeworks_pipe_end.png")
|
||||
else
|
||||
table.insert(outimgs, "pipeworks_plain.png")
|
||||
end
|
||||
if ym==1 then
|
||||
pipe_addbox(outboxes, pipe_bottomstub)
|
||||
table.insert(outsel, pipe_selectboxes[3])
|
||||
table.insert(outimgs, "pipeworks_pipe_end.png")
|
||||
else
|
||||
table.insert(outimgs, "pipeworks_plain.png")
|
||||
end
|
||||
if xp==1 then
|
||||
pipe_addbox(outboxes, pipe_rightstub)
|
||||
table.insert(outsel, pipe_selectboxes[2])
|
||||
table.insert(outimgs, "pipeworks_pipe_end.png")
|
||||
else
|
||||
table.insert(outimgs, "pipeworks_plain.png")
|
||||
end
|
||||
if xm==1 then
|
||||
pipe_addbox(outboxes, pipe_leftstub)
|
||||
table.insert(outsel, pipe_selectboxes[1])
|
||||
table.insert(outimgs, "pipeworks_pipe_end.png")
|
||||
else
|
||||
table.insert(outimgs, "pipeworks_plain.png")
|
||||
end
|
||||
if zp==1 then
|
||||
pipe_addbox(outboxes, pipe_backstub)
|
||||
table.insert(outsel, pipe_selectboxes[6])
|
||||
table.insert(outimgs, "pipeworks_pipe_end.png")
|
||||
else
|
||||
table.insert(outimgs, "pipeworks_plain.png")
|
||||
end
|
||||
if zm==1 then
|
||||
pipe_addbox(outboxes, pipe_frontstub)
|
||||
table.insert(outsel, pipe_selectboxes[5])
|
||||
table.insert(outimgs, "pipeworks_pipe_end.png")
|
||||
else
|
||||
table.insert(outimgs, "pipeworks_plain.png")
|
||||
end
|
||||
|
||||
local jx = xp+xm
|
||||
local jy = yp+ym
|
||||
local jz = zp+zm
|
||||
|
||||
if (jx+jy+jz) == 1 then
|
||||
if xm == 1 then
|
||||
table.remove(outimgs, 3)
|
||||
table.insert(outimgs, 3, "^pipeworks_plain.png")
|
||||
function pipeworks.node_is_owned(pos, placer)
|
||||
local ownername = false
|
||||
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
|
||||
if HasOwner(pos, placer) then -- returns true if the node is owned
|
||||
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
|
||||
if type(getLastOwner) == "function" then -- ...is an old version
|
||||
ownername = getLastOwner(pos)
|
||||
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
|
||||
ownername = GetNodeOwnerName(pos)
|
||||
else
|
||||
ownername = S("someone")
|
||||
end
|
||||
end
|
||||
end
|
||||
if xp == 1 then
|
||||
table.remove(outimgs, 4)
|
||||
table.insert(outimgs, 4, "^pipeworks_plain.png")
|
||||
|
||||
elseif type(isprotect)=="function" then -- glomie's protection mod
|
||||
if not isprotect(5, pos, placer) then
|
||||
ownername = S("someone")
|
||||
end
|
||||
if ym == 1 then
|
||||
table.remove(outimgs, 1)
|
||||
table.insert(outimgs, 1, "^pipeworks_plain.png")
|
||||
end
|
||||
if xp == 1 then
|
||||
table.remove(outimgs, 2)
|
||||
table.insert(outimgs, 2, "^pipeworks_plain.png")
|
||||
end
|
||||
if zm == 1 then
|
||||
table.remove(outimgs, 5)
|
||||
table.insert(outimgs, 5, "^pipeworks_plain.png")
|
||||
end
|
||||
if zp == 1 then
|
||||
table.remove(outimgs, 6)
|
||||
table.insert(outimgs, 6, "^pipeworks_plain.png")
|
||||
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
|
||||
if not protector.can_dig(5, pos, placer) then
|
||||
ownername = S("someone")
|
||||
end
|
||||
end
|
||||
|
||||
if jx+jy+jz >= 2 then
|
||||
pipe_addbox(outboxes, pipe_bendsphere)
|
||||
end
|
||||
|
||||
if (jx==2 and jy~=2 and jz~=2) then
|
||||
table.remove(outimgs, 5)
|
||||
table.remove(outimgs, 5)
|
||||
table.insert(outimgs, 5, pipeworks_liquid_texture.."^pipeworks_windowed_XXXXX.png")
|
||||
table.insert(outimgs, 5, pipeworks_liquid_texture.."^pipeworks_windowed_XXXXX.png")
|
||||
end
|
||||
|
||||
if (jx~=2 and jy~=2 and jz==2) or (jx~=2 and jy==2 and jz~=2) then
|
||||
table.remove(outimgs, 3)
|
||||
table.remove(outimgs, 3)
|
||||
table.insert(outimgs, 3, pipeworks_liquid_texture.."^pipeworks_windowed_XXXXX.png")
|
||||
table.insert(outimgs, 3, pipeworks_liquid_texture.."^pipeworks_windowed_XXXXX.png")
|
||||
end
|
||||
|
||||
local pname = xm..xp..ym..yp..zm..zp
|
||||
local pgroups = ""
|
||||
|
||||
if pname ~= "110000" then
|
||||
pgroups = {snappy=3, pipe=1, not_in_creative_inventory=1}
|
||||
pipedesc = "Pipe segment (empty, "..pname..")... You hacker, you."
|
||||
if ownername ~= false then
|
||||
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
|
||||
return true
|
||||
else
|
||||
pgroups = {snappy=3, pipe=1}
|
||||
pipedesc = "Pipe segment"
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_node("pipeworks:pipe_"..pname.."_empty", {
|
||||
description = pipedesc,
|
||||
drawtype = "nodebox",
|
||||
tiles = pipes_fix_image_names(outimgs, "_empty"),
|
||||
paramtype = "light",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = outsel
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = outboxes
|
||||
},
|
||||
groups = pgroups,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
drop = "pipeworks:pipe_110000_empty",
|
||||
pipelike=1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("pipeworks:pipe_"..pname.."_loaded", {
|
||||
description = "Pipe segment (loaded, "..pname..")... You hacker, you.",
|
||||
drawtype = "nodebox",
|
||||
tiles = pipes_fix_image_names(outimgs, "_loaded"),
|
||||
paramtype = "light",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = outsel
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = outboxes
|
||||
},
|
||||
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
drop = "pipeworks:pipe_110000_empty",
|
||||
pipelike=1,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("pipelike",1)
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipe_scanforobjects(pos)
|
||||
end
|
||||
})
|
||||
table.insert(pipes_empty_nodenames,"pipeworks:pipe_"..pname.."_empty") -- for the abms
|
||||
table.insert(pipes_full_nodenames,"pipeworks:pipe_"..pname.."_loaded") -- for bacon
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("pipeworks").."/tubes.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/devices.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/autoplace.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/crafts.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/flowing_logic.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/compat.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/item_transport.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/autocrafter.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/deployer.lua")
|
||||
dofile(minetest.get_modpath("pipeworks").."/node_breaker.lua")
|
||||
function pipeworks.replace_name(tbl,tr,name)
|
||||
local ntbl={}
|
||||
for key,i in pairs(tbl) do
|
||||
if type(i)=="string" then
|
||||
ntbl[key]=string.gsub(i,tr,name)
|
||||
elseif type(i)=="table" then
|
||||
ntbl[key]=pipeworks.replace_name(i,tr,name)
|
||||
else
|
||||
ntbl[key]=i
|
||||
end
|
||||
end
|
||||
return ntbl
|
||||
end
|
||||
|
||||
-------------------------------------------
|
||||
-- Load the various other parts of the mod
|
||||
|
||||
dofile(pipeworks.modpath.."/models.lua")
|
||||
dofile(pipeworks.modpath.."/autoplace_pipes.lua")
|
||||
dofile(pipeworks.modpath.."/autoplace_tubes.lua")
|
||||
dofile(pipeworks.modpath.."/item_transport.lua")
|
||||
dofile(pipeworks.modpath.."/flowing_logic.lua")
|
||||
dofile(pipeworks.modpath.."/crafts.lua")
|
||||
dofile(pipeworks.modpath.."/tubes.lua")
|
||||
|
||||
if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end
|
||||
if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/teleport_tube.lua") end
|
||||
if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end
|
||||
if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat.lua") end
|
||||
if pipeworks.enable_autocrafter then dofile(pipeworks.modpath.."/autocrafter.lua") end
|
||||
if pipeworks.enable_deployer then dofile(pipeworks.modpath.."/deployer.lua") end
|
||||
if pipeworks.enable_node_breaker then dofile(pipeworks.modpath.."/node_breaker.lua") end
|
||||
|
||||
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
|
||||
|
||||
print("Pipeworks loaded!")
|
||||
|
||||
|
|
|
@ -1,14 +1,91 @@
|
|||
modpath=minetest.get_modpath("pipeworks")
|
||||
dofile(pipeworks.modpath.."/compat.lua")
|
||||
|
||||
dofile(modpath.."/compat.lua")
|
||||
--and an extra function for getting the right-facing vector
|
||||
local function facedir_to_right_dir(facedir)
|
||||
|
||||
--find the other directions
|
||||
local backdir = minetest.facedir_to_dir(facedir)
|
||||
local topdir = ({[0]={x=0, y=1, z=0},
|
||||
{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}})[math.floor(facedir/4)]
|
||||
|
||||
--return a cross product
|
||||
return {x=topdir.y*backdir.z - backdir.y*topdir.z,
|
||||
y=topdir.z*backdir.x - backdir.z*topdir.x,
|
||||
z=topdir.x*backdir.y - backdir.x*topdir.y}
|
||||
end
|
||||
|
||||
minetest.register_craftitem("pipeworks:filter", {
|
||||
description = "Filter",
|
||||
stack_max = 99,
|
||||
})
|
||||
|
||||
local fakePlayer = {
|
||||
get_player_name = function() return ":pipeworks" end,
|
||||
-- any other player functions called by allow_metadata_inventory_take anywhere...
|
||||
-- perhaps a custom metaclass that errors specially when fakePlayer.<property> is not found?
|
||||
}
|
||||
|
||||
function pipeworks.tube_item(pos, item)
|
||||
-- Take item in any format
|
||||
local stack = ItemStack(item)
|
||||
local obj = minetest.add_entity(pos, "pipeworks:tubed_item")
|
||||
obj:get_luaentity():set_item(stack:to_string())
|
||||
return obj
|
||||
end
|
||||
|
||||
-- adding two tube functions
|
||||
-- can_remove(pos,node,stack,dir) returns the maximum number of items of that stack that can be removed
|
||||
-- remove_items(pos,node,stack,dir,count) removes count items and returns them
|
||||
-- both optional w/ sensible defaults and fallback to normal allow_* function
|
||||
-- XXX: possibly change insert_object to insert_item
|
||||
|
||||
-- sname = the current name to allow for, or nil if it allows anything
|
||||
|
||||
local function grabAndFire(frominv,frominvname,frompos,fromnode,sname,tube,idef,dir,all)
|
||||
for spos,stack in ipairs(frominv:get_list(frominvname)) do
|
||||
if (sname == nil and stack:get_name() ~= "") or stack:get_name() == sname then
|
||||
local doRemove = stack:get_count()
|
||||
if tube.can_remove then
|
||||
doRemove = tube.can_remove(frompos, fromnode, stack, dir)
|
||||
elseif idef.allow_metadata_inventory_take then
|
||||
doRemove = idef.allow_metadata_inventory_take(frompos, frominvname,spos, stack, fakePlayer)
|
||||
end
|
||||
-- stupid lack of continue statements grumble
|
||||
if doRemove > 0 then
|
||||
local item
|
||||
local count
|
||||
if all then
|
||||
count = math.min(stack:get_count(), doRemove)
|
||||
else
|
||||
count = 1
|
||||
end
|
||||
if tube.remove_items then
|
||||
-- it could be the entire stack...
|
||||
item = tube.remove_items(frompos, fromnode, stack, dir, count)
|
||||
else
|
||||
item = stack:take_item(count)
|
||||
frominv:set_stack(frominvname, spos, stack)
|
||||
if idef.on_metadata_inventory_take then
|
||||
idef.on_metadata_inventory_take(frompos, frominvname, spos, item, fakePlayer)
|
||||
end
|
||||
end
|
||||
local item1 = pipeworks.tube_item(vector.add(frompos, vector.multiply(dir, 1.4)), item)
|
||||
item1:get_luaentity().start_pos = vector.add(frompos, dir)
|
||||
item1:setvelocity(dir)
|
||||
item1:setacceleration({x=0, y=0, z=0})
|
||||
return true-- only fire one item, please
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_node("pipeworks:filter", {
|
||||
description = "filter",
|
||||
description = "Filter",
|
||||
tiles = {"pipeworks_filter_top.png", "pipeworks_filter_top.png", "pipeworks_filter_output.png",
|
||||
"pipeworks_filter_input.png", "pipeworks_filter_side.png", "pipeworks_filter_top.png"},
|
||||
paramtype2 = "facedir",
|
||||
|
@ -16,98 +93,267 @@ minetest.register_node("pipeworks:filter", {
|
|||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[9,9;]"..
|
||||
"list[current_name;main;0,2;8,2;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
"invsize[8,6.5;]"..
|
||||
"list[current_name;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,2.5;8,4;]")
|
||||
meta:set_string("infotext", "Filter")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
mesecons={effector={action_on=function(pos,node)
|
||||
minetest.registered_nodes[node.name].on_punch(pos,node,nil)
|
||||
end}},
|
||||
tube={connect_sides={right=1}},
|
||||
on_punch = function (pos, node, puncher)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
local frompos
|
||||
local dir
|
||||
if node.param2==0 then
|
||||
frompos={x=pos.x-1,y=pos.y,z=pos.z}
|
||||
dir={x=1,y=0,z=0}
|
||||
elseif node.param2==1 then
|
||||
frompos={x=pos.x,y=pos.y,z=pos.z+1}
|
||||
dir={x=0,y=0,z=-1}
|
||||
elseif node.param2==2 then
|
||||
frompos={x=pos.x+1,y=pos.y,z=pos.z}
|
||||
dir={x=-1,y=0,z=0}
|
||||
else
|
||||
frompos={x=pos.x,y=pos.y,z=pos.z-1}
|
||||
dir={x=0,y=0,z=1}
|
||||
end
|
||||
local fromnode=minetest.env:get_node(frompos)
|
||||
local frominv
|
||||
if not (minetest.registered_nodes[fromnode.name].tube and
|
||||
minetest.registered_nodes[fromnode.name].tube.input_inventory) then
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
local dir = facedir_to_right_dir(node.param2)
|
||||
local frompos = {x=pos.x - dir.x, y=pos.y - dir.y, z=pos.z - dir.z}
|
||||
local fromnode=minetest.get_node(frompos)
|
||||
if not fromnode then return end
|
||||
local idef = minetest.registered_nodes[fromnode.name]
|
||||
-- assert(idef)
|
||||
local tube = idef.tube
|
||||
if not (tube and tube.input_inventory) then
|
||||
return
|
||||
end
|
||||
local frommeta=minetest.env:get_meta(frompos)
|
||||
local frominvname=minetest.registered_nodes[fromnode.name].tube.input_inventory
|
||||
local frominv=frommeta:get_inventory()
|
||||
for _,filter in ipairs(inv:get_list("main")) do
|
||||
local sname=filter:get_name()
|
||||
if sname ~="" then
|
||||
for spos,stack in ipairs(frominv:get_list(frominvname)) do
|
||||
if stack:get_name()==sname then
|
||||
item=stack:take_item()
|
||||
frominv:set_stack(frominvname,spos,stack)
|
||||
pos1=pos
|
||||
item1=tube_item({x=pos1.x,y=pos1.y,z=pos1.z},item)
|
||||
item1:get_luaentity().start_pos = {x=pos1.x,y=pos1.y,z=pos1.z}
|
||||
item1:setvelocity(dir)
|
||||
item1:setacceleration({x=0, y=0, z=0})
|
||||
return
|
||||
end
|
||||
if tube.before_filter then
|
||||
tube.before_filter(frompos)
|
||||
end
|
||||
local frommeta = minetest.get_meta(frompos)
|
||||
local frominv = frommeta:get_inventory()
|
||||
|
||||
local function from_inventory(frominvname)
|
||||
local sname
|
||||
for _,filter in ipairs(inv:get_list("main")) do
|
||||
sname = filter:get_name()
|
||||
if sname ~= "" then
|
||||
-- XXX: that's a lot of parameters
|
||||
if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if inv:is_empty("main") then
|
||||
for spos,stack in ipairs(frominv:get_list(frominvname)) do
|
||||
if stack:get_name()~="" then
|
||||
item=stack:take_item()
|
||||
frominv:set_stack(frominvname,spos,stack)
|
||||
pos1=pos
|
||||
item1=tube_item({x=pos1.x,y=pos1.y,z=pos1.z},item)
|
||||
item1:get_luaentity().start_pos = {x=pos1.x,y=pos1.y,z=pos1.z}
|
||||
item1:setvelocity(dir)
|
||||
item1:setacceleration({x=0, y=0, z=0})
|
||||
return
|
||||
if inv:is_empty("main") then
|
||||
grabAndFire(frominv, frominvname, frompos, fromnode, nil, tube, idef, dir)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
if type(tube.input_inventory) == "table" then
|
||||
for _, i in ipairs(tube.input_inventory) do
|
||||
if from_inventory(i) then -- fired an item
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
from_inventory(tube.input_inventory)
|
||||
end
|
||||
|
||||
if tube.after_filter then
|
||||
tube.after_filter(frompos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craftitem("pipeworks:mese_filter", {
|
||||
description = "Mese filter",
|
||||
stack_max = 99,
|
||||
})
|
||||
|
||||
function tube_item(pos, item)
|
||||
-- Take item in any format
|
||||
local stack = ItemStack(item)
|
||||
local obj = minetest.env:add_entity(pos, "pipeworks:tubed_item")
|
||||
obj:get_luaentity():set_item(stack:to_string())
|
||||
return obj
|
||||
minetest.register_node("pipeworks:mese_filter", {
|
||||
description = "Mese filter",
|
||||
tiles = {"pipeworks_mese_filter_top.png", "pipeworks_mese_filter_top.png", "pipeworks_mese_filter_output.png",
|
||||
"pipeworks_mese_filter_input.png", "pipeworks_mese_filter_side.png", "pipeworks_mese_filter_top.png"},
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,mesecon=2},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,6.5;]"..
|
||||
"list[current_name;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,2.5;8,4;]")
|
||||
meta:set_string("infotext", "Mese filter")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
mesecons={effector={action_on=function(pos,node)
|
||||
minetest.registered_nodes[node.name].on_punch(pos,node,nil)
|
||||
end}},
|
||||
tube={connect_sides={right=1}},
|
||||
on_punch = function (pos, node, puncher)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
local dir = facedir_to_right_dir(node.param2)
|
||||
local frompos = {x=pos.x - dir.x, y=pos.y - dir.y, z=pos.z - dir.z}
|
||||
local fromnode=minetest.get_node(frompos)
|
||||
local idef = minetest.registered_nodes[fromnode.name]
|
||||
-- assert(idef)
|
||||
local tube = idef.tube
|
||||
if not (tube and tube.input_inventory) then
|
||||
return
|
||||
end
|
||||
|
||||
if tube.before_filter then
|
||||
tube.before_filter(frompos)
|
||||
end
|
||||
local frommeta = minetest.get_meta(frompos)
|
||||
local frominv = frommeta:get_inventory()
|
||||
|
||||
local function from_inventory(frominvname)
|
||||
local sname
|
||||
for _,filter in ipairs(inv:get_list("main")) do
|
||||
sname = filter:get_name()
|
||||
if sname ~= "" then
|
||||
-- XXX: that's a lot of parameters
|
||||
if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir, true) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
if inv:is_empty("main") then
|
||||
grabAndFire(frominv, frominvname, frompos, fromnode, nil, tube, idef, dir, true)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
if type(tube.input_inventory) == "table" then
|
||||
for _, i in ipairs(tube.input_inventory) do
|
||||
if from_inventory(i) then -- fired an item
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
from_inventory(tube.input_inventory)
|
||||
end
|
||||
|
||||
if tube.after_filter then
|
||||
tube.after_filter(frompos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local function roundpos(pos)
|
||||
return {x=math.floor(pos.x+0.5),y=math.floor(pos.y+0.5),z=math.floor(pos.z+0.5)}
|
||||
end
|
||||
|
||||
local function addVect(pos,vect)
|
||||
return {x=pos.x+vect.x,y=pos.y+vect.y,z=pos.z+vect.z}
|
||||
end
|
||||
|
||||
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}}
|
||||
|
||||
function pipeworks.notvel(tbl, vel)
|
||||
local tbl2={}
|
||||
for _,val in ipairs(tbl) do
|
||||
if val.x ~= -vel.x or val.y ~= -vel.y or val.z ~= -vel.z then table.insert(tbl2, val) end
|
||||
end
|
||||
return tbl2
|
||||
end
|
||||
|
||||
local function go_next(pos, velocity, stack)
|
||||
local chests = {}
|
||||
local tubes = {}
|
||||
local cnode = minetest.get_node(pos)
|
||||
local cmeta = minetest.get_meta(pos)
|
||||
local n
|
||||
local can_go
|
||||
local speed = math.abs(velocity.x + velocity.y + velocity.z)
|
||||
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
|
||||
if minetest.registered_nodes[cnode.name] and minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then
|
||||
can_go = minetest.registered_nodes[cnode.name].tube.can_go(pos, cnode, vel, stack)
|
||||
else
|
||||
can_go = pipeworks.notvel(adjlist, vel)
|
||||
end
|
||||
local meta = nil
|
||||
for _,vect in ipairs(can_go) do
|
||||
local npos = addVect(pos,vect)
|
||||
local node = minetest.get_node(npos)
|
||||
local tube_receiver = minetest.get_item_group(node.name,"tubedevice_receiver")
|
||||
meta = minetest.get_meta(npos)
|
||||
local tubelike = meta:get_int("tubelike")
|
||||
if tube_receiver == 1 then
|
||||
if minetest.registered_nodes[node.name].tube and
|
||||
minetest.registered_nodes[node.name].tube.can_insert and
|
||||
minetest.registered_nodes[node.name].tube.can_insert(npos, node, stack, vect) then
|
||||
local i = #chests + 1
|
||||
chests[i] = {}
|
||||
chests[i].pos = npos
|
||||
chests[i].vect = vect
|
||||
end
|
||||
elseif tubelike == 1 then
|
||||
local i = #tubes + 1
|
||||
tubes[i] = {}
|
||||
tubes[i].pos = npos
|
||||
tubes[i].vect = vect
|
||||
end
|
||||
end
|
||||
if chests[1] == nil then--no chests found
|
||||
if tubes[1] == nil then
|
||||
return 0
|
||||
else
|
||||
n = (cmeta:get_int("tubedir")%(#tubes)) + 1
|
||||
if pipeworks.enable_cyclic_mode then
|
||||
cmeta:set_int("tubedir",n)
|
||||
end
|
||||
velocity.x = tubes[n].vect.x*vel.speed
|
||||
velocity.y = tubes[n].vect.y*vel.speed
|
||||
velocity.z = tubes[n].vect.z*vel.speed
|
||||
end
|
||||
else
|
||||
n = (cmeta:get_int("tubedir")%(#chests))+1
|
||||
if pipeworks.enable_cyclic_mode then
|
||||
cmeta:set_int("tubedir",n)
|
||||
end
|
||||
velocity.x = chests[n].vect.x*speed
|
||||
velocity.y = chests[n].vect.y*speed
|
||||
velocity.z = chests[n].vect.z*speed
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
minetest.register_entity("pipeworks:tubed_item", {
|
||||
initial_properties = {
|
||||
hp_max = 1,
|
||||
physical = false,
|
||||
collisionbox = {0,0,0,0,0,0},
|
||||
-- collisionbox = {0,0,0,0,0,0},
|
||||
collisionbox = {0.1,0.1,0.1,0.1,0.1,0.1},
|
||||
visual = "sprite",
|
||||
visual_size = {x=0.5, y=0.5},
|
||||
textures = {""},
|
||||
|
@ -153,15 +399,14 @@ minetest.register_entity("pipeworks:tubed_item", {
|
|||
end,
|
||||
|
||||
get_staticdata = function(self)
|
||||
if self.start_pos==nil then return end
|
||||
local velocity=self.object:getvelocity()
|
||||
--self.object:setvelocity({x=0,y=0,z=0})
|
||||
self.object:setpos(self.start_pos)
|
||||
return minetest.serialize({
|
||||
itemstring=self.itemstring,
|
||||
velocity=velocity,
|
||||
start_pos=self.start_pos
|
||||
})
|
||||
if self.start_pos==nil then return end
|
||||
local velocity=self.object:getvelocity()
|
||||
self.object:setpos(self.start_pos)
|
||||
return minetest.serialize({
|
||||
itemstring=self.itemstring,
|
||||
velocity=velocity,
|
||||
start_pos=self.start_pos
|
||||
})
|
||||
end,
|
||||
|
||||
on_activate = function(self, staticdata)
|
||||
|
@ -184,199 +429,118 @@ minetest.register_entity("pipeworks:tubed_item", {
|
|||
end,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
if self.start_pos then
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.env:get_node(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
tubelike=meta:get_int("tubelike")
|
||||
local stack = ItemStack(self.itemstring)
|
||||
local drop_pos=nil
|
||||
if self.start_pos==nil then
|
||||
local pos = self.object:getpos()
|
||||
self.start_pos=roundpos(pos)
|
||||
end
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.get_node(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local tubelike = meta:get_int("tubelike")
|
||||
local stack = ItemStack(self.itemstring)
|
||||
local drop_pos = nil
|
||||
|
||||
local velocity=self.object:getvelocity()
|
||||
local velocity=self.object:getvelocity()
|
||||
|
||||
if velocity==nil then return end
|
||||
if velocity == nil then return end
|
||||
|
||||
local velocitycopy={x=velocity.x,y=velocity.y,z=velocity.z}
|
||||
|
||||
local moved=false
|
||||
local speed=math.abs(velocity.x+velocity.y+velocity.z)
|
||||
local vel={x=velocity.x/speed,y=velocity.y/speed,z=velocity.z/speed}
|
||||
|
||||
if math.abs(vel.x)==1 then
|
||||
local next_node=math.abs(pos.x-self.start_pos.x)
|
||||
local velocitycopy = {x = velocity.x, y = velocity.y, z = velocity.z}
|
||||
|
||||
local moved = false
|
||||
local speed = math.abs(velocity.x+velocity.y+velocity.z)
|
||||
local vel = {x = velocity.x/speed, y = velocity.y/speed, z = velocity.z/speed, speed = speed}
|
||||
|
||||
if math.abs(vel.x) == 1 then
|
||||
local next_node = math.abs(pos.x-self.start_pos.x)
|
||||
if next_node >= 1 then
|
||||
self.start_pos.x = self.start_pos.x+vel.x
|
||||
moved = true
|
||||
end
|
||||
elseif math.abs(vel.y) == 1 then
|
||||
local next_node = math.abs(pos.y-self.start_pos.y)
|
||||
if next_node >= 1 then
|
||||
self.start_pos.x=self.start_pos.x+vel.x
|
||||
moved=true
|
||||
end
|
||||
elseif math.abs(vel.y)==1 then
|
||||
local next_node=math.abs(pos.y-self.start_pos.y)
|
||||
if next_node >= 1 then
|
||||
self.start_pos.y=self.start_pos.y+vel.y
|
||||
moved=true
|
||||
self.start_pos.y = self.start_pos.y+vel.y
|
||||
moved = true
|
||||
end
|
||||
elseif math.abs(vel.z)==1 then
|
||||
local next_node=math.abs(pos.z-self.start_pos.z)
|
||||
if next_node >= 1 then
|
||||
self.start_pos.z=self.start_pos.z+vel.z
|
||||
moved=true
|
||||
elseif math.abs(vel.z) == 1 then
|
||||
local next_node = math.abs(pos.z-self.start_pos.z)
|
||||
if next_node >= 1 then
|
||||
self.start_pos.z = self.start_pos.z+vel.z
|
||||
moved = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local sposcopy={x=self.start_pos.x,y=self.start_pos.y,z=self.start_pos.z}
|
||||
|
||||
node = minetest.env:get_node(self.start_pos)
|
||||
if moved and minetest.get_item_group(node.name,"tubedevice_receiver")==1 then
|
||||
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)
|
||||
else
|
||||
leftover = stack
|
||||
end
|
||||
--drop_pos=minetest.env:find_node_near(self.start_pos,1,"air")
|
||||
--if drop_pos and not leftover:is_empty() then minetest.item_drop(leftover,"",drop_pos) end
|
||||
--self.object:remove()
|
||||
if leftover:is_empty() then
|
||||
self.object:remove()
|
||||
|
||||
local sposcopy = {x = self.start_pos.x, y = self.start_pos.y, z = self.start_pos.z}
|
||||
|
||||
node = minetest.get_node(self.start_pos)
|
||||
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
|
||||
local leftover = nil
|
||||
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)
|
||||
else
|
||||
leftover = stack
|
||||
end
|
||||
if leftover:is_empty() then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
velocity.x = -velocity.x
|
||||
velocity.y = -velocity.y
|
||||
velocity.z = -velocity.z
|
||||
self.object:setvelocity(velocity)
|
||||
self:set_item(leftover:to_string())
|
||||
return
|
||||
end
|
||||
velocity.x=-velocity.x
|
||||
velocity.y=-velocity.y
|
||||
velocity.z=-velocity.z
|
||||
self.object:setvelocity(velocity)
|
||||
self:set_item(leftover:to_string())
|
||||
return
|
||||
end
|
||||
|
||||
if moved then
|
||||
if go_next (self.start_pos, velocity, stack)==0 then
|
||||
drop_pos=minetest.env:find_node_near({x=self.start_pos.x+velocity.x,y=self.start_pos.y+velocity.y,z=self.start_pos.z+velocity.z}, 1, "air")
|
||||
if drop_pos then
|
||||
minetest.item_drop(stack, "", drop_pos)
|
||||
self.object:remove()
|
||||
|
||||
if moved then
|
||||
if go_next (self.start_pos, velocity, stack) == 0 then
|
||||
drop_pos = minetest.find_node_near(vector.add(self.start_pos, velocity), 1, "air")
|
||||
if drop_pos then
|
||||
minetest.item_drop(stack, "", drop_pos)
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z or
|
||||
self.start_pos.x~=sposcopy.x or self.start_pos.y~=sposcopy.y or self.start_pos.z~=sposcopy.z then
|
||||
self.object:setpos(self.start_pos)
|
||||
self.object:setvelocity(velocity)
|
||||
end
|
||||
end
|
||||
|
||||
if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z or
|
||||
self.start_pos.x~=sposcopy.x or self.start_pos.y~=sposcopy.y or self.start_pos.z~=sposcopy.z then
|
||||
self.object:setpos(self.start_pos)
|
||||
self.object:setvelocity(velocity)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
function addVect(pos,vect)
|
||||
return {x=pos.x+vect.x,y=pos.y+vect.y,z=pos.z+vect.z}
|
||||
end
|
||||
|
||||
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}}
|
||||
|
||||
function notvel(tbl,vel)
|
||||
tbl2={}
|
||||
for _,val in ipairs(tbl) do
|
||||
if val.x~=-vel.x or val.y~=-vel.y or val.z~=-vel.z then table.insert(tbl2,val) end
|
||||
end
|
||||
return tbl2
|
||||
end
|
||||
|
||||
function go_next(pos,velocity,stack)
|
||||
local chests={}
|
||||
local tubes={}
|
||||
local cnode=minetest.env:get_node(pos)
|
||||
local cmeta=minetest.env:get_meta(pos)
|
||||
local node
|
||||
local meta
|
||||
local tubelike
|
||||
local tube_receiver
|
||||
local len=1
|
||||
local n
|
||||
local can_go
|
||||
local speed=math.abs(velocity.x+velocity.y+velocity.z)
|
||||
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
|
||||
if minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then
|
||||
can_go=minetest.registered_nodes[cnode.name].tube.can_go(pos,node,vel,stack)
|
||||
else
|
||||
can_go=notvel(adjlist,vel)
|
||||
end
|
||||
for _,vect in ipairs(can_go) do
|
||||
npos=addVect(pos,vect)
|
||||
node=minetest.env:get_node(npos)
|
||||
tube_receiver=minetest.get_item_group(node.name,"tubedevice_receiver")
|
||||
meta=minetest.env:get_meta(npos)
|
||||
tubelike=meta:get_int("tubelike")
|
||||
if tube_receiver==1 then
|
||||
if minetest.registered_nodes[node.name].tube and
|
||||
minetest.registered_nodes[node.name].tube.can_insert and
|
||||
minetest.registered_nodes[node.name].tube.can_insert(npos,node,stack,vect) then
|
||||
local i=1
|
||||
repeat
|
||||
if chests[i]==nil then break end
|
||||
i=i+1
|
||||
until false
|
||||
chests[i]={}
|
||||
chests[i].pos=npos
|
||||
chests[i].vect=vect
|
||||
end
|
||||
elseif tubelike==1 then
|
||||
local i=1
|
||||
repeat
|
||||
if tubes[i]==nil then break end
|
||||
i=i+1
|
||||
until false
|
||||
tubes[i]={}
|
||||
tubes[i].pos=npos
|
||||
tubes[i].vect=vect
|
||||
if minetest.get_modpath("mesecons_mvps") ~= nil then
|
||||
local function add_table(table,toadd)
|
||||
local i = 1
|
||||
while true do
|
||||
o = table[i]
|
||||
if o == toadd then return end
|
||||
if o == nil then break end
|
||||
i = i+1
|
||||
end
|
||||
table[i] = toadd
|
||||
end
|
||||
if chests[1]==nil then--no chests found
|
||||
if tubes[1]==nil then
|
||||
return 0
|
||||
else
|
||||
local i=1
|
||||
repeat
|
||||
if tubes[i]==nil then break end
|
||||
i=i+1
|
||||
until false
|
||||
n=meta:get_int("tubedir")+1
|
||||
repeat
|
||||
if n>=i then
|
||||
n=n-i+1
|
||||
else
|
||||
break
|
||||
mesecon:register_mvps_unmov("pipeworks:tubed_item")
|
||||
mesecon:register_on_mvps_move(function(moved_nodes)
|
||||
local objects_to_move = {}
|
||||
for _, n in ipairs(moved_nodes) do
|
||||
local objects = minetest.get_objects_inside_radius(n.oldpos, 1)
|
||||
for _, obj in ipairs(objects) do
|
||||
local entity = obj:get_luaentity()
|
||||
if entity and entity.name == "pipeworks:tubed_item" then
|
||||
--objects_to_move[#objects_to_move+1] = obj
|
||||
add_table(objects_to_move, obj)
|
||||
end
|
||||
until false
|
||||
meta:set_int("tubedir",n)
|
||||
velocity.x=tubes[n].vect.x*vel.speed
|
||||
velocity.y=tubes[n].vect.y*vel.speed
|
||||
velocity.z=tubes[n].vect.z*vel.speed
|
||||
end
|
||||
else
|
||||
local i=1
|
||||
repeat
|
||||
if chests[i]==nil then break end
|
||||
i=i+1
|
||||
until false
|
||||
n=meta:get_int("tubedir")+1
|
||||
repeat
|
||||
if n>=i then
|
||||
n=n-i+1
|
||||
else
|
||||
break
|
||||
end
|
||||
until false
|
||||
velocity.x=chests[n].vect.x*speed
|
||||
velocity.y=chests[n].vect.y*speed
|
||||
velocity.z=chests[n].vect.z*speed
|
||||
end
|
||||
return 1
|
||||
end
|
||||
end
|
||||
if #objects_to_move > 0 then
|
||||
local dir = vector.subtract(moved_nodes[1].pos, moved_nodes[1].oldpos)
|
||||
for _, obj in ipairs(objects_to_move) do
|
||||
local entity = obj:get_luaentity()
|
||||
obj:setpos(vector.add(obj:getpos(), dir))
|
||||
entity.start_pos = vector.add(entity.start_pos, dir)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,202 @@
|
|||
---------------------
|
||||
-- The various models
|
||||
|
||||
-- Pipe models
|
||||
|
||||
pipeworks.pipe_leftstub = {
|
||||
{ -32/64, -2/64, -6/64, 1/64, 2/64, 6/64 }, -- pipe segment against -X face
|
||||
{ -32/64, -4/64, -5/64, 1/64, 4/64, 5/64 },
|
||||
{ -32/64, -5/64, -4/64, 1/64, 5/64, 4/64 },
|
||||
{ -32/64, -6/64, -2/64, 1/64, 6/64, 2/64 },
|
||||
|
||||
{ -32/64, -3/64, -8/64, -30/64, 3/64, 8/64 }, -- (the flange for it)
|
||||
{ -32/64, -5/64, -7/64, -30/64, 5/64, 7/64 },
|
||||
{ -32/64, -6/64, -6/64, -30/64, 6/64, 6/64 },
|
||||
{ -32/64, -7/64, -5/64, -30/64, 7/64, 5/64 },
|
||||
{ -32/64, -8/64, -3/64, -30/64, 8/64, 3/64 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_rightstub = {
|
||||
{ -1/64, -2/64, -6/64, 32/64, 2/64, 6/64 }, -- pipe segment against +X face
|
||||
{ -1/64, -4/64, -5/64, 32/64, 4/64, 5/64 },
|
||||
{ -1/64, -5/64, -4/64, 32/64, 5/64, 4/64 },
|
||||
{ -1/64, -6/64, -2/64, 32/64, 6/64, 2/64 },
|
||||
|
||||
{ 30/64, -3/64, -8/64, 32/64, 3/64, 8/64 }, -- (the flange for it)
|
||||
{ 30/64, -5/64, -7/64, 32/64, 5/64, 7/64 },
|
||||
{ 30/64, -6/64, -6/64, 32/64, 6/64, 6/64 },
|
||||
{ 30/64, -7/64, -5/64, 32/64, 7/64, 5/64 },
|
||||
{ 30/64, -8/64, -3/64, 32/64, 8/64, 3/64 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_bottomstub = {
|
||||
{ -2/64, -32/64, -6/64, 2/64, 1/64, 6/64 }, -- pipe segment against -Y face
|
||||
{ -4/64, -32/64, -5/64, 4/64, 1/64, 5/64 },
|
||||
{ -5/64, -32/64, -4/64, 5/64, 1/64, 4/64 },
|
||||
{ -6/64, -32/64, -2/64, 6/64, 1/64, 2/64 },
|
||||
|
||||
{ -3/64, -32/64, -8/64, 3/64, -30/64, 8/64 }, -- (the flange for it)
|
||||
{ -5/64, -32/64, -7/64, 5/64, -30/64, 7/64 },
|
||||
{ -6/64, -32/64, -6/64, 6/64, -30/64, 6/64 },
|
||||
{ -7/64, -32/64, -5/64, 7/64, -30/64, 5/64 },
|
||||
{ -8/64, -32/64, -3/64, 8/64, -30/64, 3/64 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_topstub = {
|
||||
{ -2/64, -1/64, -6/64, 2/64, 32/64, 6/64 }, -- pipe segment against +Y face
|
||||
{ -4/64, -1/64, -5/64, 4/64, 32/64, 5/64 },
|
||||
{ -5/64, -1/64, -4/64, 5/64, 32/64, 4/64 },
|
||||
{ -6/64, -1/64, -2/64, 6/64, 32/64, 2/64 },
|
||||
|
||||
{ -3/64, 30/64, -8/64, 3/64, 32/64, 8/64 }, -- (the flange for it)
|
||||
{ -5/64, 30/64, -7/64, 5/64, 32/64, 7/64 },
|
||||
{ -6/64, 30/64, -6/64, 6/64, 32/64, 6/64 },
|
||||
{ -7/64, 30/64, -5/64, 7/64, 32/64, 5/64 },
|
||||
{ -8/64, 30/64, -3/64, 8/64, 32/64, 3/64 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_frontstub = {
|
||||
{ -6/64, -2/64, -32/64, 6/64, 2/64, 1/64 }, -- pipe segment against -Z face
|
||||
{ -5/64, -4/64, -32/64, 5/64, 4/64, 1/64 },
|
||||
{ -4/64, -5/64, -32/64, 4/64, 5/64, 1/64 },
|
||||
{ -2/64, -6/64, -32/64, 2/64, 6/64, 1/64 },
|
||||
|
||||
{ -8/64, -3/64, -32/64, 8/64, 3/64, -30/64 }, -- (the flange for it)
|
||||
{ -7/64, -5/64, -32/64, 7/64, 5/64, -30/64 },
|
||||
{ -6/64, -6/64, -32/64, 6/64, 6/64, -30/64 },
|
||||
{ -5/64, -7/64, -32/64, 5/64, 7/64, -30/64 },
|
||||
{ -3/64, -8/64, -32/64, 3/64, 8/64, -30/64 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_backstub = {
|
||||
{ -6/64, -2/64, -1/64, 6/64, 2/64, 32/64 }, -- pipe segment against -Z face
|
||||
{ -5/64, -4/64, -1/64, 5/64, 4/64, 32/64 },
|
||||
{ -4/64, -5/64, -1/64, 4/64, 5/64, 32/64 },
|
||||
{ -2/64, -6/64, -1/64, 2/64, 6/64, 32/64 },
|
||||
|
||||
{ -8/64, -3/64, 30/64, 8/64, 3/64, 32/64 }, -- (the flange for it)
|
||||
{ -7/64, -5/64, 30/64, 7/64, 5/64, 32/64 },
|
||||
{ -6/64, -6/64, 30/64, 6/64, 6/64, 32/64 },
|
||||
{ -5/64, -7/64, 30/64, 5/64, 7/64, 32/64 },
|
||||
{ -3/64, -8/64, 30/64, 3/64, 8/64, 32/64 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_boxes = {pipeworks.pipe_leftstub, pipeworks.pipe_rightstub, pipeworks.pipe_bottomstub, pipeworks.pipe_topstub, pipeworks.pipe_frontstub, pipeworks.pipe_backstub}
|
||||
|
||||
pipeworks.pipe_selectboxes = {
|
||||
{ -32/64, -8/64, -8/64, 8/64, 8/64, 8/64 },
|
||||
{ -8/64 , -8/64, -8/64, 32/64, 8/64, 8/64 },
|
||||
{ -8/64 , -32/64, -8/64, 8/64, 8/64, 8/64 },
|
||||
{ -8/64 , -8/64, -8/64, 8/64, 32/64, 8/64 },
|
||||
{ -8/64 , -8/64, -32/64, 8/64, 8/64, 8/64 },
|
||||
{ -8/64 , -8/64, -8/64, 8/64, 8/64, 32/64 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_bendsphere = {
|
||||
{ -4/64, -4/64, -4/64, 4/64, 4/64, 4/64 },
|
||||
{ -5/64, -3/64, -3/64, 5/64, 3/64, 3/64 },
|
||||
{ -3/64, -5/64, -3/64, 3/64, 5/64, 3/64 },
|
||||
{ -3/64, -3/64, -5/64, 3/64, 3/64, 5/64 }
|
||||
}
|
||||
|
||||
-- Tube models
|
||||
|
||||
pipeworks.tube_leftstub = {
|
||||
{ -32/64, -9/64, -9/64, 9/64, 9/64, 9/64 }, -- tube segment against -X face
|
||||
}
|
||||
|
||||
pipeworks.tube_rightstub = {
|
||||
{ -9/64, -9/64, -9/64, 32/64, 9/64, 9/64 }, -- tube segment against +X face
|
||||
}
|
||||
|
||||
pipeworks.tube_bottomstub = {
|
||||
{ -9/64, -32/64, -9/64, 9/64, 9/64, 9/64 }, -- tube segment against -Y face
|
||||
}
|
||||
|
||||
pipeworks.tube_topstub = {
|
||||
{ -9/64, -9/64, -9/64, 9/64, 32/64, 9/64 }, -- tube segment against +Y face
|
||||
}
|
||||
|
||||
pipeworks.tube_frontstub = {
|
||||
{ -9/64, -9/64, -32/64, 9/64, 9/64, 9/64 }, -- tube segment against -Z face
|
||||
}
|
||||
|
||||
pipeworks.tube_backstub = {
|
||||
{ -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}
|
||||
|
||||
pipeworks.tube_selectboxes = {
|
||||
{ -32/64, -10/64, -10/64, 10/64, 10/64, 10/64 },
|
||||
{ -10/64 , -10/64, -10/64, 32/64, 10/64, 10/64 },
|
||||
{ -10/64 , -32/64, -10/64, 10/64, 10/64, 10/64 },
|
||||
{ -10/64 , -10/64, -10/64, 10/64, 32/64, 10/64 },
|
||||
{ -10/64 , -10/64, -32/64, 10/64, 10/64, 10/64 },
|
||||
{ -10/64 , -10/64, -10/64, 10/64, 10/64, 32/64 }
|
||||
}
|
||||
|
||||
-- Device models
|
||||
|
||||
pipeworks.pipe_pumpbody = {
|
||||
{ -7/16, -6/16, -7/16, 7/16, 5/16, 7/16 },
|
||||
{ -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_valvebody = {
|
||||
{ -4/16, -4/16, -4/16, 4/16, 4/16, 4/16 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_valvehandle_on = {
|
||||
{ -5/16, 4/16, -1/16, 0, 5/16, 1/16 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_valvehandle_off = {
|
||||
{ -1/16, 4/16, -5/16, 1/16, 5/16, 0 }
|
||||
}
|
||||
|
||||
pipeworks.pipe_sensorbody = {
|
||||
{ -3/16, -2/16, -2/16, 3/16, 2/16, 2/16 }
|
||||
}
|
||||
|
||||
pipeworks.spigot_bottomstub = {
|
||||
{ -2/64, -16/64, -6/64, 2/64, 1/64, 6/64 }, -- pipe segment against -Y face
|
||||
{ -4/64, -16/64, -5/64, 4/64, 1/64, 5/64 },
|
||||
{ -5/64, -16/64, -4/64, 5/64, 1/64, 4/64 },
|
||||
{ -6/64, -16/64, -2/64, 6/64, 1/64, 2/64 },
|
||||
|
||||
{ -3/64, -16/64, -8/64, 3/64, -14/64, 8/64 }, -- (the flange for it)
|
||||
{ -5/64, -16/64, -7/64, 5/64, -14/64, 7/64 },
|
||||
{ -6/64, -16/64, -6/64, 6/64, -14/64, 6/64 },
|
||||
{ -7/64, -16/64, -5/64, 7/64, -14/64, 5/64 },
|
||||
{ -8/64, -16/64, -3/64, 8/64, -14/64, 3/64 }
|
||||
}
|
||||
|
||||
pipeworks.spigot_stream = {
|
||||
{ -3/64, (-41/64)-0.01, -5/64, 3/64, -16/64, 5/64 },
|
||||
{ -4/64, (-41/64)-0.01, -4/64, 4/64, -16/64, 4/64 },
|
||||
{ -5/64, (-41/64)-0.01, -3/64, 5/64, -16/64, 3/64 }
|
||||
}
|
||||
|
||||
pipeworks.entry_panel = {
|
||||
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
|
||||
}
|
||||
|
||||
pipeworks.fountainhead_model = {
|
||||
{ -2/64, -32/64, -6/64, 2/64, 21/64, 6/64 }, -- main segment
|
||||
{ -4/64, -32/64, -5/64, 4/64, 21/64, 5/64 },
|
||||
{ -5/64, -32/64, -4/64, 5/64, 21/64, 4/64 },
|
||||
{ -6/64, -32/64, -2/64, 6/64, 21/64, 2/64 },
|
||||
|
||||
{ -3/64, -32/64, -8/64, 3/64, -30/64, 8/64 }, -- bottom flange
|
||||
{ -5/64, -32/64, -7/64, 5/64, -30/64, 7/64 },
|
||||
{ -6/64, -32/64, -6/64, 6/64, -30/64, 6/64 },
|
||||
{ -7/64, -32/64, -5/64, 7/64, -30/64, 5/64 },
|
||||
{ -8/64, -32/64, -3/64, 8/64, -30/64, 3/64 },
|
||||
|
||||
{ -3/64, 20/64, -8/64, 3/64, 32/64, 8/64 }, -- top flange/outlet
|
||||
{ -5/64, 20/64, -7/64, 5/64, 32/64, 7/64 },
|
||||
{ -6/64, 20/64, -6/64, 6/64, 32/64, 6/64 },
|
||||
{ -7/64, 20/64, -5/64, 7/64, 32/64, 5/64 },
|
||||
{ -8/64, 20/64, -3/64, 8/64, 32/64, 3/64 }
|
||||
}
|
|
@ -1,36 +1,197 @@
|
|||
|
||||
--register aliases for when someone had technic installed, but then uninstalled it but not pipeworks
|
||||
minetest.register_alias("technic:nodebreaker_off", "pipeworks:nodebreaker_off")
|
||||
minetest.register_alias("technic:nodebreaker_on", "pipeworks:nodebreaker_on")
|
||||
minetest.register_alias("technic:node_breaker_off", "pipeworks:nodebreaker_off") --old name
|
||||
minetest.register_alias("technic:node_breaker_on", "pipeworks:nodebreaker_on") --old name
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'pipeworks:nodebreaker_off 1',
|
||||
recipe = {
|
||||
{'default:wood', 'default:pick_mese','default:wood'},
|
||||
{'group:wood', 'default:pick_mese','group:wood'},
|
||||
{'default:stone', 'mesecons:piston','default:stone'},
|
||||
{'default:stone', 'mesecons:mesecon','default:stone'},
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
function hacky_swap_node(pos,name)
|
||||
local node=minetest.env:get_node(pos)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local meta0=meta:to_table()
|
||||
node.name=name
|
||||
minetest.env:add_node(pos, node)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
meta:from_table(meta0)
|
||||
local function swap_node(pos, name)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
--define the functions from https://github.com/minetest/minetest/pull/834 while waiting for the devs to notice it
|
||||
local function dir_to_facedir(dir, is6d)
|
||||
--account for y if requested
|
||||
if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
|
||||
|
||||
--from above
|
||||
if dir.y < 0 then
|
||||
if math.abs(dir.x) > math.abs(dir.z) then
|
||||
if dir.x < 0 then
|
||||
return 19
|
||||
else
|
||||
return 13
|
||||
end
|
||||
else
|
||||
if dir.z < 0 then
|
||||
return 10
|
||||
else
|
||||
return 4
|
||||
end
|
||||
end
|
||||
|
||||
--from below
|
||||
else
|
||||
if math.abs(dir.x) > math.abs(dir.z) then
|
||||
if dir.x < 0 then
|
||||
return 15
|
||||
else
|
||||
return 17
|
||||
end
|
||||
else
|
||||
if dir.z < 0 then
|
||||
return 6
|
||||
else
|
||||
return 8
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--otherwise, place horizontally
|
||||
elseif math.abs(dir.x) > math.abs(dir.z) then
|
||||
if dir.x < 0 then
|
||||
return 3
|
||||
else
|
||||
return 1
|
||||
end
|
||||
else
|
||||
if dir.z < 0 then
|
||||
return 2
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
node_breaker_on = function(pos, node)
|
||||
local function delay(x)
|
||||
return (function() return x end)
|
||||
end
|
||||
|
||||
local function break_node (pos, facedir)
|
||||
--locate the outgoing velocity, front, and back of the node via facedir_to_dir
|
||||
if type(facedir) ~= "number" or facedir < 0 or facedir > 23 then return end
|
||||
|
||||
local vel = minetest.facedir_to_dir(facedir)
|
||||
local front = {x=pos.x - vel.x, y=pos.y - vel.y, z=pos.z - vel.z}
|
||||
|
||||
local node = minetest.get_node(front)
|
||||
--if node.name == "air" or node.name == "ignore" then
|
||||
-- return nil
|
||||
--elseif minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].liquidtype ~= "none" then
|
||||
-- return nil
|
||||
--end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local pick_inv = "pick"
|
||||
local pick = inv:get_stack("pick", 1)
|
||||
if pick:is_empty() then
|
||||
pick = ItemStack("default:pick_mese")
|
||||
inv:set_stack("ghost_pick", 1, pick)
|
||||
pick_inv = "ghost_pick"
|
||||
end
|
||||
local pitch
|
||||
local yaw
|
||||
if vel.z < 0 then
|
||||
yaw = 0
|
||||
pitch = 0
|
||||
elseif vel.z > 0 then
|
||||
yaw = math.pi
|
||||
pitch = 0
|
||||
elseif vel.x < 0 then
|
||||
yaw = 3*math.pi/2
|
||||
pitch = 0
|
||||
elseif vel.x > 0 then
|
||||
yaw = math.pi/2
|
||||
pitch = 0
|
||||
elseif vel.y > 0 then
|
||||
yaw = 0
|
||||
pitch = -math.pi/2
|
||||
else
|
||||
yaw = 0
|
||||
pitch = math.pi/2
|
||||
end
|
||||
local digger = {
|
||||
get_inventory_formspec = delay(""),
|
||||
get_look_dir = delay({x = -vel.x, y = -vel.y, z = -vel.z}),
|
||||
get_look_pitch = delay(pitch),
|
||||
get_look_yaw = delay(yaw),
|
||||
get_player_control = delay({jump=false, right=false, left=false, LMB=false, RMB=false, sneak=false, aux1=false, down=false, up=false}),
|
||||
get_player_control_bits = delay(0),
|
||||
get_player_name = delay(meta:get_string("owner")),
|
||||
is_player = delay(true),
|
||||
set_inventory_formspec = delay(),
|
||||
getpos = delay({x = pos.x, y = pos.y - 1.5, z = pos.z}), -- Player height
|
||||
get_hp = delay(20),
|
||||
get_inventory = delay(inv),
|
||||
get_wielded_item = delay(pick),
|
||||
get_wield_index = delay(1),
|
||||
get_wield_list = delay(pick_inv),
|
||||
moveto = delay(),
|
||||
punch = delay(),
|
||||
remove = delay(),
|
||||
right_click = delay(),
|
||||
setpos = delay(),
|
||||
set_hp = delay(),
|
||||
set_properties = delay(),
|
||||
set_wielded_item = function(self, stack)
|
||||
if stack:get_name() == pick:get_name() then
|
||||
inv:set_stack(pick_inv, 1, stack)
|
||||
else
|
||||
inv:add_item("main", stack)
|
||||
inv:set_stack(pick_inv, 1, ItemStack(""))
|
||||
end
|
||||
end,
|
||||
set_animation = delay(),
|
||||
set_attach = delay(),
|
||||
set_detach = delay(),
|
||||
set_bone_position = delay(),
|
||||
}
|
||||
|
||||
if pick_inv == "pick" and minetest.registered_items[pick:get_name()] and minetest.registered_items[pick:get_name()].on_use then
|
||||
local pos_under, pos_above = {x = pos.x - vel.x, y = pos.y - vel.y, z = pos.z - vel.z}, {x = pos.x - 2*vel.x, y = pos.y - 2*vel.y, z = pos.z - 2*vel.z}
|
||||
local pointed_thing = {type="node", under=pos_under, above=pos_above}
|
||||
inv:set_stack(pick_inv, 1, minetest.registered_items[pick:get_name()].on_use(pick, digger, pointed_thing) or pick)
|
||||
else
|
||||
minetest.node_dig(front, node, digger)
|
||||
end
|
||||
|
||||
for i = 1, 100 do
|
||||
local dropped_item = inv:get_stack("main", i)
|
||||
if not dropped_item:is_empty() then
|
||||
local item1 = pipeworks.tube_item({x=pos.x, y=pos.y, z=pos.z}, dropped_item)
|
||||
item1:get_luaentity().start_pos = {x=pos.x, y=pos.y, z=pos.z}
|
||||
item1:setvelocity(vel)
|
||||
item1:setacceleration({x=0, y=0, z=0})
|
||||
inv:set_stack("main", i, ItemStack(""))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local node_breaker_on = function(pos, node)
|
||||
if node.name == "pipeworks:nodebreaker_off" then
|
||||
hacky_swap_node(pos,"pipeworks:nodebreaker_on")
|
||||
break_node (pos,node.param2)
|
||||
swap_node(pos, "pipeworks:nodebreaker_on")
|
||||
break_node(pos, node.param2)
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
||||
node_breaker_off = function(pos, node)
|
||||
local node_breaker_off = function(pos, node)
|
||||
if node.name == "pipeworks:nodebreaker_on" then
|
||||
hacky_swap_node(pos,"pipeworks:nodebreaker_off")
|
||||
swap_node(pos, "pipeworks:nodebreaker_off")
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
@ -41,60 +202,191 @@ minetest.register_node("pipeworks:nodebreaker_off", {
|
|||
"pipeworks_nodebreaker_back.png","pipeworks_nodebreaker_front_off.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1},
|
||||
mesecons= {effector={action_on=node_breaker_on, action_off=node_breaker_off}},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1},
|
||||
mesecons= {effector={rules=pipeworks.rules_all,action_on=node_breaker_on, action_off=node_breaker_off}},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
tube = {connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1},
|
||||
input_inventory = "pick",
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local vel = minetest.facedir_to_dir(node.param2)
|
||||
if math.abs(vel.x) == math.abs(direction.x) and math.abs(vel.y) == math.abs(direction.y) and math.abs(vel.z) == math.abs(direction.z) then
|
||||
return stack
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:add_item("pick", stack)
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local vel = minetest.facedir_to_dir(node.param2)
|
||||
if math.abs(vel.x) == math.abs(direction.x) and math.abs(vel.y) == math.abs(direction.y) and math.abs(vel.z) == math.abs(direction.z) then
|
||||
return false
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:room_for_item("pick", stack)
|
||||
end,
|
||||
can_remove = function(pos, node, stack, dir)
|
||||
return stack:get_count()
|
||||
end},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("pick", 1)
|
||||
inv:set_size("ghost_pick", 1)
|
||||
inv:set_size("main", 100)
|
||||
--inv:set_stack("pick", 1, ItemStack("default:pick_mese"))
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,6;]"..
|
||||
"label[0,0;Node breaker]"..
|
||||
"list[current_name;pick;3.5,0;1,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]")
|
||||
end,
|
||||
|
||||
after_place_node = function (pos, placer)
|
||||
pipeworks.scan_for_tube_objects(pos, placer)
|
||||
local placer_pos = placer:getpos()
|
||||
|
||||
--correct for the player's height
|
||||
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
|
||||
|
||||
--correct for 6d facedir
|
||||
if placer_pos then
|
||||
local dir = {
|
||||
x = pos.x - placer_pos.x,
|
||||
y = pos.y - placer_pos.y,
|
||||
z = pos.z - placer_pos.z
|
||||
}
|
||||
local node = minetest.get_node(pos)
|
||||
node.param2 = dir_to_facedir(dir, true)
|
||||
minetest.set_node(pos, node)
|
||||
minetest.log("action", "real (6d) facedir: " .. node.param2)
|
||||
end
|
||||
|
||||
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local stack = oldmetadata.inventory.pick[1]
|
||||
if not stack:is_empty() then
|
||||
minetest.add_item(pos, stack)
|
||||
end
|
||||
pipeworks.scan_for_tube_objects(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("pipeworks:nodebreaker_on", {
|
||||
description = "Node Breaker",
|
||||
tile_images = {"pipeworks_nodebreaker_top_on.png","pipeworks_nodebreaker_bottom_on.png","pipeworks_nodebreaker_side2_on.png","pipeworks_nodebreaker_side1_on.png",
|
||||
"pipeworks_nodebreaker_back.png","pipeworks_nodebreaker_front_on.png"},
|
||||
mesecons= {effector={action_on=node_breaker_on, action_off=node_breaker_off}},
|
||||
mesecons= {effector={rules=pipeworks.rules_all,action_on=node_breaker_on, action_off=node_breaker_off}},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1,not_in_creative_inventory=1},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1,not_in_creative_inventory=1, tubedevice_receiver=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
function break_node (pos,n_param)
|
||||
local pos1={}
|
||||
local pos2={}
|
||||
pos1.x=pos.x
|
||||
pos1.y=pos.y
|
||||
pos1.z=pos.z
|
||||
pos2.x=pos.x
|
||||
pos2.y=pos.y
|
||||
pos2.z=pos.z
|
||||
|
||||
--param2 3=x+ 1=x- 2=z+ 0=z-
|
||||
local x_velocity=0
|
||||
local z_velocity=0
|
||||
|
||||
if n_param==3 then pos2.x=pos2.x+1 pos1.x=pos1.x-1 x_velocity=-1 end
|
||||
if n_param==2 then pos2.z=pos2.z+1 pos1.z=pos1.z-1 z_velocity=-1 end
|
||||
if n_param==1 then pos2.x=pos2.x-1 pos1.x=pos1.x+1 x_velocity=1 end
|
||||
if n_param==0 then pos2.z=pos2.z-1 pos1.x=pos1.z+1 z_velocity=1 end
|
||||
|
||||
local node=minetest.env:get_node(pos2)
|
||||
if node.name == "air" then return nil end
|
||||
if node.name == "default:lava_source" then return nil end
|
||||
if node.name == "default:lava_flowing" then return nil end
|
||||
if node.name == "default:water_source" then minetest.env:remove_node(pos2) return nil end
|
||||
if node.name == "default:water_flowing" then minetest.env:remove_node(pos2) return nil end
|
||||
if node.name == "ignore" then minetest.env:remove_node(pos2) return nil end
|
||||
local drops = minetest.get_node_drops(node.name, "default:pick_mese")
|
||||
local _, dropped_item
|
||||
for _, dropped_item in ipairs(drops) do
|
||||
local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},dropped_item)
|
||||
item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z}
|
||||
item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
|
||||
item1:setacceleration({x=0, y=0, z=0})
|
||||
drop = "pipeworks:nodebreaker_off",
|
||||
tube = {connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1},
|
||||
input_inventory = "pick",
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local vel = minetest.facedir_to_dir(node.param2)
|
||||
if math.abs(vel.x) == math.abs(direction.x) and math.abs(vel.y) == math.abs(direction.y) and math.abs(vel.z) == math.abs(direction.z) then
|
||||
return stack
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:add_item("pick", stack)
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local vel = minetest.facedir_to_dir(node.param2)
|
||||
if math.abs(vel.x) == math.abs(direction.x) and math.abs(vel.y) == math.abs(direction.y) and math.abs(vel.z) == math.abs(direction.z) then
|
||||
return false
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:room_for_item("pick", stack)
|
||||
end,
|
||||
can_remove = function(pos, node, stack, dir)
|
||||
return stack:get_count()
|
||||
end},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("pick", 1)
|
||||
inv:set_size("ghost_pick", 1)
|
||||
inv:set_size("main", 100)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,6;]"..
|
||||
"label[0,0;Node breaker]"..
|
||||
"list[current_name;pick;3.5,0;1,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]")
|
||||
--inv:set_stack("pick", 1, ItemStack("default:pick_mese"))
|
||||
end,
|
||||
after_place_node = function (pos, placer)
|
||||
pipeworks.scan_for_tube_objects(pos, placer)
|
||||
local placer_pos = placer:getpos()
|
||||
|
||||
--correct for the player's height
|
||||
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
|
||||
|
||||
--correct for 6d facedir
|
||||
if placer_pos then
|
||||
local dir = {
|
||||
x = pos.x - placer_pos.x,
|
||||
y = pos.y - placer_pos.y,
|
||||
z = pos.z - placer_pos.z
|
||||
}
|
||||
local node = minetest.get_node(pos)
|
||||
node.param2 = dir_to_facedir(dir, true)
|
||||
minetest.set_node(pos, node)
|
||||
minetest.log("action", "real (6d) facedir: " .. node.param2)
|
||||
end
|
||||
minetest.env:remove_node(pos2)
|
||||
end
|
||||
|
||||
|
||||
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local stack = oldmetadata.inventory.pick[1]
|
||||
if not stack:is_empty() then
|
||||
minetest.add_item(pos, stack)
|
||||
end
|
||||
pipeworks.scan_for_tube_objects(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,360 +0,0 @@
|
|||
-- This file is basically most of the old init.lua and only supplies the
|
||||
-- old nodes created by the previous verison of Pipeworks.
|
||||
--
|
||||
-- License: WTFPL
|
||||
--
|
||||
|
||||
local nodenames = {
|
||||
"vertical",
|
||||
"horizontal",
|
||||
"junction_xy",
|
||||
"junction_xz",
|
||||
"bend_xy_down",
|
||||
"bend_xy_up",
|
||||
"bend_xz",
|
||||
"crossing_xz",
|
||||
"crossing_xy",
|
||||
"crossing_xyz",
|
||||
"pipe_segment",
|
||||
"cap_neg_x",
|
||||
"cap_pos_x",
|
||||
"cap_neg_y",
|
||||
"cap_pos_y",
|
||||
"cap_neg_z",
|
||||
"cap_pos_z"
|
||||
}
|
||||
|
||||
local descriptions = {
|
||||
"vertical",
|
||||
"horizontal",
|
||||
"junction between X and Y axes",
|
||||
"junction between X and Z axes",
|
||||
"downward bend between X and Y axes",
|
||||
"upward bend between X and Y axes",
|
||||
"bend between X/Z axes",
|
||||
"4-way crossing between X and Z axes",
|
||||
"4-way crossing between X/Z and Y axes",
|
||||
"6-way crossing",
|
||||
"basic segment",
|
||||
"capped, negative X half only",
|
||||
"capped, positive X half only",
|
||||
"capped, negative Y half only",
|
||||
"capped, positive Y half only",
|
||||
"capped, negative Z half only",
|
||||
"capped, positive Z half only"
|
||||
}
|
||||
|
||||
local nodeimages = {
|
||||
{"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png"},
|
||||
|
||||
{"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png"},
|
||||
|
||||
{"pipeworks_plain.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png"},
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png"},
|
||||
|
||||
{"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png"},
|
||||
|
||||
-- horizontal short segment
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_plain.png",
|
||||
"pipeworks_plain.png"},
|
||||
|
||||
-- capped
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_pipe_end.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png"},
|
||||
|
||||
{"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_windowed_XXXXX.png",
|
||||
"pipeworks_pipe_end.png",
|
||||
"pipeworks_windowed_XXXXX.png"},
|
||||
}
|
||||
|
||||
local selectionboxes = {
|
||||
{ -0.15, -0.5, -0.15, 0.15, 0.5, 0.15 },
|
||||
{ -0.5, -0.15, -0.15, 0.5, 0.15, 0.15 },
|
||||
{ -0.15, -0.5, -0.15, 0.5, 0.5, 0.15 },
|
||||
{ -0.5, -0.15, -0.15, 0.5, 0.15, 0.5 },
|
||||
{ -0.15, -0.5, -0.15, 0.5, 0.15, 0.15 },
|
||||
{ -0.15, -0.15, -0.15, 0.5, 0.5, 0.15 },
|
||||
{ -0.15, -0.15, -0.15, 0.5, 0.15, 0.5 },
|
||||
{ -0.5, -0.15, -0.5, 0.5, 0.15, 0.5 },
|
||||
{ -0.5, -0.5, -0.15, 0.5, 0.5, 0.15 },
|
||||
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
{ -0.3, -0.15, -0.15, 0.3, 0.15, 0.15 },
|
||||
{ -0.5, -0.15, -0.15, 0, 0.15, 0.15 },
|
||||
{ 0, -0.15, -0.15, 0.5, 0.15, 0.15 },
|
||||
{ -0.15, -0.5, -0.15, 0.15, 0, 0.15 },
|
||||
{ -0.15, 0, -0.15, 0.15, 0.5, 0.15 },
|
||||
{ -0.15, -0.15, -0.5, 0.15, 0.15, 0 },
|
||||
{ -0.15, -0.15, 0, 0.15, 0.15, 0.5 },
|
||||
}
|
||||
|
||||
local nodeboxes = {
|
||||
{{ -0.15, -0.5 , -0.15, 0.15, -0.45, 0.15 }, -- vertical
|
||||
{ -0.1 , -0.45, -0.1 , 0.1 , 0.45, 0.1 },
|
||||
{ -0.15, 0.45, -0.15, 0.15, 0.5 , 0.15 }},
|
||||
|
||||
{{ -0.5 , -0.15, -0.15, -0.45, 0.15, 0.15 }, -- horizontal
|
||||
{ -0.45, -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 }},
|
||||
|
||||
{{ -0.15, -0.5 , -0.15, 0.15, -0.45, 0.15 }, -- vertical with X/Z junction
|
||||
{ -0.1 , -0.45, -0.1 , 0.1 , 0.45, 0.1 },
|
||||
{ -0.15, 0.45, -0.15, 0.15, 0.5 , 0.15 },
|
||||
{ 0.1 , -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 }},
|
||||
|
||||
{{ -0.15, -0.15, 0.45, 0.15, 0.15, 0.5 }, -- horizontal with X/Z junction
|
||||
{ -0.1 , -0.1 , 0.1 , 0.1 , 0.1 , 0.45 },
|
||||
{ -0.5 , -0.15, -0.15, -0.45, 0.15, 0.15 },
|
||||
{ -0.45, -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 }},
|
||||
|
||||
{{ -0.15, -0.5 , -0.15, 0.15, -0.45, 0.15 }, -- bend down from X/Z to Y axis
|
||||
{ -0.1 , -0.45, -0.1 , 0.1 , 0.1 , 0.1 },
|
||||
{ -0.1 , -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 }},
|
||||
|
||||
{{ -0.15, 0.45 , -0.15, 0.15, 0.5, 0.15 }, -- bend up from X/Z to Y axis
|
||||
{ -0.1 , -0.1 , -0.1 , 0.1 , 0.45, 0.1 },
|
||||
{ -0.1 , -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 }},
|
||||
|
||||
{{ -0.15, -0.15, 0.45, 0.15, 0.15, 0.5 }, -- bend between X and Z axes
|
||||
{ -0.1 , -0.1 , 0.1 , 0.1 , 0.1 , 0.45 },
|
||||
{ -0.1 , -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 }},
|
||||
|
||||
{{ -0.5 , -0.15, -0.15, -0.45, 0.15, 0.15 }, -- 4-way crossing between X and Z axes
|
||||
{ -0.45, -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 },
|
||||
{ -0.15, -0.15, -0.5 , 0.15, 0.15, -0.45 },
|
||||
{ -0.1 , -0.1 , -0.45, 0.1 , 0.1 , 0.45 },
|
||||
{ -0.15, -0.15, 0.45, 0.15, 0.15, 0.5 }},
|
||||
|
||||
{{ -0.15, -0.5 , -0.15, 0.15, -0.45, 0.15 }, -- 4-way crossing between X/Z and Y axes
|
||||
{ -0.1 , -0.45, -0.1 , 0.1 , 0.45, 0.1 },
|
||||
{ -0.15, 0.45, -0.15, 0.15, 0.5 , 0.15 },
|
||||
{ -0.5 , -0.15, -0.15, -0.45, 0.15, 0.15 },
|
||||
{ -0.45, -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 }},
|
||||
|
||||
{{ -0.5 , -0.15, -0.15, -0.45, 0.15, 0.15 }, -- 6-way crossing (all 3 axes)
|
||||
{ -0.45, -0.1 , -0.1 , 0.45, 0.1 , 0.1 },
|
||||
{ 0.45, -0.15, -0.15, 0.5 , 0.15, 0.15 },
|
||||
{ -0.15, -0.15, -0.5 , 0.15, 0.15, -0.45 },
|
||||
{ -0.1 , -0.1 , -0.45, 0.1 , 0.1 , 0.45 },
|
||||
{ -0.15, -0.15, 0.45, 0.15, 0.15, 0.5 },
|
||||
{ -0.15, -0.5 , -0.15, 0.15, -0.45, 0.15 },
|
||||
{ -0.1 , -0.45, -0.1 , 0.1 , 0.45, 0.1 },
|
||||
{ -0.15, 0.45, -0.15, 0.15, 0.5 , 0.15 }},
|
||||
|
||||
{{ -0.3 , -0.15, -0.15, -0.25, 0.15, 0.15 }, -- main center segment
|
||||
{ -0.25, -0.1 , -0.1 , 0.25, 0.1 , 0.1 },
|
||||
{ 0.25, -0.15, -0.15, 0.3 , 0.15, 0.15 }},
|
||||
|
||||
{{ -0.5, -0.15, -0.15, -0.45, 0.15, 0.15 }, -- anchored at -X
|
||||
{ -0.45, -0.1, -0.1, -0.2, 0.1, 0.1 },
|
||||
{ -0.2, -0.15, -0.15, -0.15, 0.15, 0.15 },
|
||||
{ -0.15, -0.12, -0.12, -0.1, 0.12, 0.12 },
|
||||
{ -0.1, -0.08, -0.08, -0.05, 0.08, 0.08 },
|
||||
{ -0.05, -0.04, -0.04, 0, 0.04, 0.04 }},
|
||||
|
||||
{{ 0.45, -0.15, -0.15, 0.5, 0.15, 0.15 }, -- anchored at +X
|
||||
{ 0.2, -0.1, -0.1, 0.45, 0.1, 0.1 },
|
||||
{ 0.15, -0.15, -0.15, 0.2, 0.15, 0.15 },
|
||||
{ 0.1, -0.12, -0.12, 0.15, 0.12, 0.12 },
|
||||
{ 0.05, -0.08, -0.08, 0.1, 0.08, 0.08 },
|
||||
{ 0, -0.04, -0.04, 0.05, 0.04, 0.04 }},
|
||||
|
||||
{{ -0.15, -0.5, -0.15, 0.15, -0.45, 0.15 }, -- anchored at -Y
|
||||
{ -0.1, -0.45, -0.1, 0.1, -0.2, 0.1 },
|
||||
{ -0.15, -0.2, -0.15, 0.15, -0.15, 0.15 },
|
||||
{ -0.12, -0.15, -0.12, 0.12, -0.1, 0.12 },
|
||||
{ -0.08, -0.1, -0.08, 0.08, -0.05, 0.08 },
|
||||
{ -0.04, -0.05, -0.04, 0.04, 0, 0.04 }},
|
||||
|
||||
{{ -0.15, 0.45, -0.15, 0.15, 0.5, 0.15 }, -- anchored at +Y
|
||||
{ -0.1, 0.2, -0.1, 0.1, 0.45, 0.1 },
|
||||
{ -0.15, 0.15, -0.15, 0.15, 0.2, 0.15 },
|
||||
{ -0.12, 0.1, -0.12, 0.12, 0.15, 0.12 },
|
||||
{ -0.08, 0.05, -0.08, 0.08, 0.1, 0.08 } ,
|
||||
{ -0.04, 0, -0.04, 0.04, 0.05, 0.04 }},
|
||||
|
||||
{{ -0.15, -0.15, -0.5, 0.15, 0.15, -0.45 }, -- anchored at -Z
|
||||
{ -0.1, -0.1, -0.45, 0.1, 0.1, -0.2 },
|
||||
{ -0.15, -0.15, -0.2, 0.15, 0.15, -0.15 },
|
||||
{ -0.12, -0.12, -0.15, 0.12, 0.12, -0.1 },
|
||||
{ -0.08, -0.08, -0.1, 0.08, 0.08, -0.05 },
|
||||
{ -0.04, -0.04, -0.05, 0.04, 0.04, 0 }},
|
||||
|
||||
{{ -0.15, -0.15, 0.45, 0.15, 0.15, 0.5 }, -- anchored at +Z
|
||||
{ -0.1, -0.1, 0.2, 0.1, 0.1, 0.45 },
|
||||
{ -0.15, -0.15, 0.15, 0.15, 0.15, 0.2 },
|
||||
{ -0.12, -0.12, 0.1, 0.12, 0.12, 0.15 },
|
||||
{ -0.08, -0.08, 0.05, 0.08, 0.08, 0.1 },
|
||||
{ -0.04, -0.04, 0, 0.04, 0.04, 0.05 }},
|
||||
}
|
||||
|
||||
function fix_image_names(node, replacement)
|
||||
outtable={}
|
||||
for i in ipairs(nodeimages[node]) do
|
||||
outtable[i]=string.gsub(nodeimages[node][i], "_XXXXX", replacement)
|
||||
end
|
||||
|
||||
return outtable
|
||||
end
|
||||
|
||||
-- Now define the actual nodes
|
||||
|
||||
for node in ipairs(nodenames) do
|
||||
|
||||
if node ~= 2 then
|
||||
pgroups = {snappy=3, pipe=1, not_in_creative_inventory=1}
|
||||
else
|
||||
pgroups = {snappy=3, pipe=1}
|
||||
end
|
||||
|
||||
minetest.register_node("pipeworks:"..nodenames[node], {
|
||||
description = "Empty Pipe ("..descriptions[node]..")",
|
||||
drawtype = "nodebox",
|
||||
tiles = fix_image_names(node, "_empty"),
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = selectionboxes[node],
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodeboxes[node]
|
||||
},
|
||||
groups = pgroups,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
stack_max = 99,
|
||||
drop = "pipeworks:pipe"
|
||||
})
|
||||
|
||||
minetest.register_node("pipeworks:"..nodenames[node].."_loaded", {
|
||||
description = "Loaded Pipe ("..descriptions[node]..")",
|
||||
drawtype = "nodebox",
|
||||
tiles = fix_image_names(node, "_loaded"),
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = selectionboxes[node],
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodeboxes[node]
|
||||
},
|
||||
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
stack_max = 99,
|
||||
drop = "pipeworks:pipe"
|
||||
})
|
||||
end
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
-- This file supplies the steel pipes
|
||||
|
||||
local REGISTER_COMPATIBILITY = true
|
||||
|
||||
local pipes_empty_nodenames = {}
|
||||
local pipes_full_nodenames = {}
|
||||
|
||||
local vti = {4, 3, 2, 1, 6, 5}
|
||||
local cconnects = {{}, {1}, {1, 2}, {1, 3}, {1, 3, 5}, {1, 2, 3}, {1, 2, 3, 5}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}
|
||||
for index, connects in ipairs(cconnects) do
|
||||
local outboxes = {}
|
||||
local outsel = {}
|
||||
local outimgs = {}
|
||||
|
||||
for i = 1, 6 do
|
||||
outimgs[vti[i]] = "pipeworks_plain.png"
|
||||
end
|
||||
|
||||
local jx = 0
|
||||
local jy = 0
|
||||
local jz = 0
|
||||
for _, v in ipairs(connects) do
|
||||
if v == 1 or v == 2 then
|
||||
jx = jx + 1
|
||||
elseif v == 3 or v == 4 then
|
||||
jy = jy + 1
|
||||
else
|
||||
jz = jz + 1
|
||||
end
|
||||
pipeworks.add_node_box(outboxes, pipeworks.pipe_boxes[v])
|
||||
table.insert(outsel, pipeworks.pipe_selectboxes[v])
|
||||
outimgs[vti[v]] = "pipeworks_pipe_end.png"
|
||||
end
|
||||
|
||||
if #connects == 1 then
|
||||
local v = connects[1]
|
||||
v = v-1 + 2*(v%2) -- Opposite side
|
||||
outimgs[vti[v]] = "^pipeworks_plain.png"
|
||||
end
|
||||
|
||||
if #connects >= 2 then
|
||||
pipeworks.add_node_box(outboxes, pipeworks.pipe_bendsphere)
|
||||
end
|
||||
|
||||
if jx == 2 and jy ~= 2 and jz ~= 2 then
|
||||
outimgs[5] = pipeworks.liquid_texture.."^pipeworks_windowed_XXXXX.png"
|
||||
outimgs[6] = outimgs[5]
|
||||
end
|
||||
|
||||
local pgroups = {snappy = 3, pipe = 1, not_in_creative_inventory = 1}
|
||||
local pipedesc = "Pipe segement".." "..dump(connects).."... You hacker, you."
|
||||
local image = nil
|
||||
|
||||
if #connects == 0 then
|
||||
pgroups = {snappy = 3, tube = 1}
|
||||
pipedesc = "Pipe segment"
|
||||
image = "pipeworks_pipe_inv.png"
|
||||
end
|
||||
|
||||
--table.insert(pipeworks.tubenodes, name.."_"..tname)
|
||||
|
||||
minetest.register_node("pipeworks:pipe_"..index.."_empty", {
|
||||
description = pipedesc,
|
||||
drawtype = "nodebox",
|
||||
tiles = pipeworks.fix_image_names(outimgs, "_empty"),
|
||||
sunlight_propagates = true,
|
||||
inventory_image = image,
|
||||
wield_image = image,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = outsel
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = outboxes
|
||||
},
|
||||
groups = pgroups,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
drop = "pipeworks:pipe_1_empty",
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end
|
||||
})
|
||||
|
||||
local pgroups = {snappy = 3, pipe = 1, not_in_creative_inventory = 1}
|
||||
|
||||
minetest.register_node("pipeworks:pipe_"..index.."_loaded", {
|
||||
description = pipedesc,
|
||||
drawtype = "nodebox",
|
||||
tiles = pipeworks.fix_image_names(outimgs, "_loaded"),
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = outsel
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = outboxes
|
||||
},
|
||||
groups = pgroups,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
walkable = true,
|
||||
drop = "pipeworks:pipe_1_empty",
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(pipes_empty_nodenames, "pipeworks:pipe_"..index.."_empty")
|
||||
table.insert(pipes_full_nodenames, "pipeworks:pipe_"..index.."_loaded")
|
||||
end
|
||||
|
||||
|
||||
|
||||
if REGISTER_COMPATIBILITY then
|
||||
local cempty = "pipeworks:pipe_compatibility_empty"
|
||||
local cloaded = "pipeworks:pipe_compatibility_loaded"
|
||||
minetest.register_node(cempty, {
|
||||
drawtype = "airlike",
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
inventory_image = "pipeworks_pipe_inv.png",
|
||||
wield_image = "pipeworks_pipe_inv.png",
|
||||
description = "Pipe Segment (legacy)",
|
||||
groups = {not_in_creative_inventory = 1, pipe_to_update = 1},
|
||||
drop = "pipeworks:pipe_1_empty",
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
})
|
||||
minetest.register_node(cloaded, {
|
||||
drawtype = "airlike",
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
inventory_image = "pipeworks_pipe_inv.png",
|
||||
groups = {not_in_creative_inventory = 1, pipe_to_update = 1},
|
||||
drop = "pipeworks:pipe_1_empty",
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end,
|
||||
})
|
||||
for xm = 0, 1 do
|
||||
for xp = 0, 1 do
|
||||
for ym = 0, 1 do
|
||||
for yp = 0, 1 do
|
||||
for zm = 0, 1 do
|
||||
for zp = 0, 1 do
|
||||
local pname = xm..xp..ym..yp..zm..zp
|
||||
minetest.register_alias("pipeworks:pipe_"..pname.."_empty", cempty)
|
||||
minetest.register_alias("pipeworks:pipe_"..pname.."_loaded", cloaded)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:pipe_to_update"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local minp = {x = pos.x-1, y = pos.y-1, z = pos.z-1}
|
||||
local maxp = {x = pos.x+1, y = pos.y+1, z = pos.z+1}
|
||||
if table.getn(minetest.find_nodes_in_area(minp, maxp, "ignore")) == 0 then
|
||||
pipeworks.scan_for_pipe_objects(pos)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(pipes_empty_nodenames,"pipeworks:valve_on_empty")
|
||||
table.insert(pipes_empty_nodenames,"pipeworks:valve_off_empty")
|
||||
table.insert(pipes_empty_nodenames,"pipeworks:entry_panel_empty")
|
||||
table.insert(pipes_empty_nodenames,"pipeworks:flow_sensor_empty")
|
||||
|
||||
table.insert(pipes_full_nodenames,"pipeworks:valve_on_loaded")
|
||||
table.insert(pipes_full_nodenames,"pipeworks:entry_panel_loaded")
|
||||
table.insert(pipes_full_nodenames,"pipeworks:flow_sensor_loaded")
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = pipes_empty_nodenames,
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
pipeworks.check_for_inflows(pos,node)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = pipes_full_nodenames,
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
pipeworks.check_sources(pos,node)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"pipeworks:spigot","pipeworks:spigot_pouring"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
pipeworks.spigot_check(pos,node)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"pipeworks:fountainhead","pipeworks:fountainhead_pouring"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
pipeworks.fountainhead_check(pos,node)
|
||||
end
|
||||
})
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
filename=minetest.get_worldpath() .. "/teleport_tubes"
|
||||
local filename=minetest.get_worldpath() .. "/teleport_tubes"
|
||||
|
||||
function read_file()
|
||||
local function read_file()
|
||||
local f = io.open(filename, "r")
|
||||
if f==nil then return {} end
|
||||
local t = f:read("*all")
|
||||
|
@ -10,26 +10,38 @@ function read_file()
|
|||
return minetest.deserialize(t)
|
||||
end
|
||||
|
||||
function write_file(tbl)
|
||||
local function write_file(tbl)
|
||||
local f = io.open(filename, "w")
|
||||
f:write(minetest.serialize(tbl))
|
||||
f:close()
|
||||
end
|
||||
|
||||
function add_tube_in_file(pos,channel)
|
||||
tbl=read_file()
|
||||
local function update_pos_in_file(pos)
|
||||
local tbl=read_file()
|
||||
for _,val in ipairs(tbl) do
|
||||
if val.x==pos.x and val.y==pos.y and val.z==pos.z then
|
||||
local meta = minetest.get_meta(val)
|
||||
val.channel = meta:get_string("channel")
|
||||
val.cr = meta:get_int("can_receive")
|
||||
end
|
||||
end
|
||||
write_file(tbl)
|
||||
end
|
||||
|
||||
local function add_tube_in_file(pos,channel, cr)
|
||||
local tbl=read_file()
|
||||
for _,val in ipairs(tbl) do
|
||||
if val.x==pos.x and val.y==pos.y and val.z==pos.z then
|
||||
return
|
||||
end
|
||||
end
|
||||
table.insert(tbl,{x=pos.x,y=pos.y,z=pos.z,channel=channel})
|
||||
table.insert(tbl,{x=pos.x,y=pos.y,z=pos.z,channel=channel,cr=cr})
|
||||
write_file(tbl)
|
||||
end
|
||||
|
||||
function remove_tube_in_file(pos)
|
||||
tbl=read_file()
|
||||
newtbl={}
|
||||
local function remove_tube_in_file(pos)
|
||||
local tbl=read_file()
|
||||
local newtbl={}
|
||||
for _,val in ipairs(tbl) do
|
||||
if val.x~=pos.x or val.y~=pos.y or val.z~=pos.z then
|
||||
table.insert(newtbl,val)
|
||||
|
@ -38,53 +50,113 @@ function remove_tube_in_file(pos)
|
|||
write_file(newtbl)
|
||||
end
|
||||
|
||||
function get_tubes_in_file(pos,channel)
|
||||
tbl=read_file()
|
||||
newtbl={}
|
||||
local function get_tubes_in_file(pos,channel)
|
||||
local tbl=read_file()
|
||||
local newtbl={}
|
||||
local changed=false
|
||||
for _,val in ipairs(tbl) do
|
||||
if val.channel==channel and (val.x~=pos.x or val.y~=pos.y or val.z~=pos.z) then
|
||||
local node = minetest.get_node(val)
|
||||
local meta = minetest.get_meta(val)
|
||||
-- That shouldn't be needed anymore since the mvps callback, but we leave it nevertheless
|
||||
if node.name~="ignore" and (val.channel~=meta:get_string("channel") or val.cr~=meta:get_int("can_receive")) then
|
||||
val.channel=meta:get_string("channel")
|
||||
val.cr=meta:get_int("can_receive")
|
||||
changed=true
|
||||
end
|
||||
if val.cr==1 and val.channel==channel and (val.x~=pos.x or val.y~=pos.y or val.z~=pos.z) then
|
||||
table.insert(newtbl,val)
|
||||
end
|
||||
end
|
||||
if changed then write_file(tbl) end
|
||||
return newtbl
|
||||
end
|
||||
|
||||
teleport_noctr_textures={"pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png",
|
||||
local teleport_noctr_textures={"pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png",
|
||||
"pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png"}
|
||||
teleport_plain_textures={"pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png",
|
||||
local teleport_plain_textures={"pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png",
|
||||
"pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png"}
|
||||
teleport_end_textures={"pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png",
|
||||
local teleport_end_textures={"pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png",
|
||||
"pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png"}
|
||||
teleport_short_texture="pipeworks_teleport_tube_short.png"
|
||||
teleport_inv_texture="pipeworks_teleport_tube_inv.png"
|
||||
local teleport_short_texture="pipeworks_teleport_tube_short.png"
|
||||
local teleport_inv_texture="pipeworks_teleport_tube_inv.png"
|
||||
|
||||
register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube segment",teleport_plain_textures,
|
||||
teleport_noctr_textures,teleport_end_textures,teleport_short_texture,teleport_inv_texture,
|
||||
{tube={can_go=function(pos,node,velocity,stack)
|
||||
velocity.x=0
|
||||
velocity.y=0
|
||||
velocity.z=0
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
channel=meta:get_string("channel")
|
||||
goto=get_tubes_in_file(pos,channel)
|
||||
if goto[1]==nil then return {} end
|
||||
pos.x=goto[1].x
|
||||
pos.y=goto[1].y
|
||||
pos.z=goto[1].z
|
||||
return meseadjlist
|
||||
end},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("channel","0")
|
||||
meta:set_string("formspec","size[9,1;]field[0,0.5;9,1;channel;Channel:;${channel}]")
|
||||
add_tube_in_file(pos,"0")
|
||||
end,
|
||||
on_receive_fields = function(pos,formname,fields,sender)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("channel",fields.channel)
|
||||
remove_tube_in_file(pos)
|
||||
add_tube_in_file(pos,fields.channel)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
remove_tube_in_file(pos)
|
||||
end})
|
||||
pipeworks.register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube segment",teleport_plain_textures,
|
||||
teleport_noctr_textures,teleport_end_textures,teleport_short_texture,teleport_inv_texture, {
|
||||
tube = {
|
||||
can_go = function(pos,node,velocity,stack)
|
||||
velocity.x = 0
|
||||
velocity.y = 0
|
||||
velocity.z = 0
|
||||
local meta = minetest.get_meta(pos)
|
||||
local channel = meta:get_string("channel")
|
||||
local target = get_tubes_in_file(pos,channel)
|
||||
if target[1] == nil then return {} end
|
||||
local d = math.random(1,#target)
|
||||
pos.x = target[d].x
|
||||
pos.y = target[d].y
|
||||
pos.z = target[d].z
|
||||
return pipeworks.meseadjlist
|
||||
end
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("channel","")
|
||||
meta:set_int("can_receive",1)
|
||||
meta:set_string("formspec","size[9,1;]"..
|
||||
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
|
||||
"button[8,0;1,1;bt;On]")
|
||||
add_tube_in_file(pos,"")
|
||||
end,
|
||||
on_receive_fields = function(pos,formname,fields,sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
--check for private channels
|
||||
if fields.channel ~= nil then
|
||||
local name, mode = fields.channel:match("^([^:;]+)([:;])")
|
||||
if name and mode and name ~= sender:get_player_name() then
|
||||
|
||||
--channels starting with '[name]:' can only be used by the named player
|
||||
if mode == ":" then
|
||||
minetest.chat_send_player(sender:get_player_name(), "Sorry, channel '"..fields.channel.."' is reserved for exclusive use by "..name)
|
||||
return
|
||||
|
||||
--channels starting with '[name];' can be used by other players, but cannot be received from
|
||||
elseif mode == ";" and (meta:get_int("can_receive") ~= 0) == (fields["bt"] == nil) then
|
||||
minetest.chat_send_player(sender:get_player_name(), "Sorry, receiving from channel '"..fields.channel.."' is reserved for "..name)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fields.channel==nil then fields.channel=meta:get_string("channel") end
|
||||
meta:set_string("channel",fields.channel)
|
||||
remove_tube_in_file(pos)
|
||||
local cr = meta:get_int("can_receive")
|
||||
if fields["bt"] then
|
||||
cr=1-cr
|
||||
meta:set_int("can_receive",cr)
|
||||
if cr==1 then
|
||||
meta:set_string("formspec","size[9,1;]"..
|
||||
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
|
||||
"button[8,0;1,1;bt;On]")
|
||||
else
|
||||
meta:set_string("formspec","size[9,1;]"..
|
||||
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
|
||||
"button[8,0;1,1;bt;Off]")
|
||||
end
|
||||
end
|
||||
add_tube_in_file(pos,fields.channel, cr)
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
remove_tube_in_file(pos)
|
||||
end})
|
||||
|
||||
if minetest.get_modpath("mesecons_mvps") ~= nil then
|
||||
mesecon:register_on_mvps_move(function(moved_nodes)
|
||||
for _, n in ipairs(moved_nodes) do
|
||||
if string.find(n.node.name, "pipeworks:teleport_tube") ~= nil then
|
||||
update_pos_in_file(n.pos)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
Before Width: | Height: | Size: 691 B |
Before Width: | Height: | Size: 688 B |
After Width: | Height: | Size: 440 B |
After Width: | Height: | Size: 569 B |
After Width: | Height: | Size: 169 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 721 B |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 690 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 163 B |
Before Width: | Height: | Size: 150 B After Width: | Height: | Size: 100 B |
Before Width: | Height: | Size: 160 B After Width: | Height: | Size: 100 B |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 755 B |
Before Width: | Height: | Size: 757 B After Width: | Height: | Size: 512 B |
Before Width: | Height: | Size: 835 B After Width: | Height: | Size: 819 B |
Before Width: | Height: | Size: 800 B After Width: | Height: | Size: 685 B |
Before Width: | Height: | Size: 719 B After Width: | Height: | Size: 560 B |
Before Width: | Height: | Size: 908 B After Width: | Height: | Size: 841 B |
Before Width: | Height: | Size: 908 B After Width: | Height: | Size: 841 B |
Before Width: | Height: | Size: 910 B After Width: | Height: | Size: 841 B |
Before Width: | Height: | Size: 842 B After Width: | Height: | Size: 819 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 853 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 760 B |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 210 B |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 193 B |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 212 B |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 212 B |
After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 160 B After Width: | Height: | Size: 100 B |
After Width: | Height: | Size: 210 B |
After Width: | Height: | Size: 193 B |
After Width: | Height: | Size: 212 B |
After Width: | Height: | Size: 212 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 699 B |
After Width: | Height: | Size: 983 B |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 628 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 721 B |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 690 B |
Before Width: | Height: | Size: 632 B After Width: | Height: | Size: 651 B |
Before Width: | Height: | Size: 556 B After Width: | Height: | Size: 657 B |
Before Width: | Height: | Size: 549 B After Width: | Height: | Size: 660 B |
Before Width: | Height: | Size: 653 B After Width: | Height: | Size: 607 B |
Before Width: | Height: | Size: 659 B After Width: | Height: | Size: 563 B |
Before Width: | Height: | Size: 616 B After Width: | Height: | Size: 598 B |
Before Width: | Height: | Size: 610 B After Width: | Height: | Size: 608 B |
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 601 B |
Before Width: | Height: | Size: 598 B After Width: | Height: | Size: 610 B |