minetest-mods/pipeworks/init.lua

158 lines
5.4 KiB
Lua
Raw Normal View History

2021-04-27 12:18:37 +02:00
local function pdofile(n,...)
local ok,err=pcall(dofile,n,...)
2021-04-27 12:16:40 +02:00
if not ok then
minetest.after(60,minetest.chat_send_all,"*** Error: "..err)
end
end
2021-04-27 12:09:07 +02:00
2019-12-14 17:47:31 +01:00
-- Pipeworks mod by Vanessa Ezekowitz - 2013-07-13
--
-- This mod supplies various steel pipes and plastic pneumatic tubes
-- and devices that they can connect to.
--
pipeworks = {}
local DEBUG = false
pipeworks.worldpath = minetest.get_worldpath()
pipeworks.modpath = minetest.get_modpath("pipeworks")
2021-04-27 12:16:40 +02:00
pdofile(pipeworks.modpath.."/default_settings.lua")
2019-12-14 17:47:31 +01:00
-- Read the external config file if it exists.
local worldsettingspath = pipeworks.worldpath.."/pipeworks_settings.txt"
local worldsettingsfile = io.open(worldsettingspath, "r")
if worldsettingsfile then
worldsettingsfile:close()
2020-10-07 12:41:08 +02:00
if dofile(worldsettingspath) == "defect" then
return
end
2019-12-14 17:47:31 +01:00
end
if pipeworks.toggles.pipe_mode == "pressure" then
minetest.log("warning", "pipeworks pressure logic mode comes with caveats and differences in behaviour, you have been warned!")
end
-- Random variables
pipeworks.expect_infinite_stacks = true
if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("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.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
pipeworks.liquid_texture = "default_water.png"
pipeworks.button_off = {text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}
pipeworks.button_on = {text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"}
pipeworks.button_base = "image_button[0,4.3;1,0.6"
pipeworks.button_label = "label[0.9,4.31;Allow splitting incoming stacks from tubes]"
-- 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
return outtable
end
function pipeworks.add_node_box(t, b)
if not t or not b then return end
for i in ipairs(b)
do table.insert(t, b[i])
end
end
function pipeworks.may_configure(pos, player)
local name = player:get_player_name()
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if owner ~= "" then -- wielders and filters
return owner == name
end
return not minetest.is_protected(pos, name)
end
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
pipeworks.logger = function(msg)
print("[pipeworks] "..msg)
end
-------------------------------------------
-- Load the various other parts of the mod
-- early auto-detection for finite water mode if not explicitly disabled
if pipeworks.toggles.finite_water == nil then
2021-04-27 12:16:40 +02:00
pdofile(pipeworks.modpath.."/autodetect-finite-water.lua")
2019-12-14 17:47:31 +01:00
end
2021-04-27 12:16:40 +02:00
pdofile(pipeworks.modpath.."/common.lua")
pdofile(pipeworks.modpath.."/models.lua")
pdofile(pipeworks.modpath.."/autoplace_pipes.lua")
pdofile(pipeworks.modpath.."/autoplace_tubes.lua")
pdofile(pipeworks.modpath.."/luaentity.lua")
pdofile(pipeworks.modpath.."/item_transport.lua")
pdofile(pipeworks.modpath.."/flowing_logic.lua")
pdofile(pipeworks.modpath.."/crafts.lua")
pdofile(pipeworks.modpath.."/tube_registration.lua")
pdofile(pipeworks.modpath.."/routing_tubes.lua")
pdofile(pipeworks.modpath.."/sorting_tubes.lua")
pdofile(pipeworks.modpath.."/vacuum_tubes.lua")
pdofile(pipeworks.modpath.."/signal_tubes.lua")
pdofile(pipeworks.modpath.."/decorative_tubes.lua")
pdofile(pipeworks.modpath.."/filter-injector.lua")
pdofile(pipeworks.modpath.."/trashcan.lua")
pdofile(pipeworks.modpath.."/wielder.lua")
2019-12-14 17:47:31 +01:00
local logicdir = "/pressure_logic/"
-- note that even with these files the new flow logic is not yet default.
-- registration will take place but no actual ABMs/node logic will be installed,
-- unless the toggle flag is specifically enabled in the per-world settings flag.
2021-04-27 12:16:40 +02:00
pdofile(pipeworks.modpath..logicdir.."flowable_node_registry.lua")
pdofile(pipeworks.modpath..logicdir.."abms.lua")
pdofile(pipeworks.modpath..logicdir.."abm_register.lua")
pdofile(pipeworks.modpath..logicdir.."flowable_node_registry_install.lua")
if pipeworks.enable_pipes then pdofile(pipeworks.modpath.."/pipes.lua") end
if pipeworks.enable_teleport_tube then pdofile(pipeworks.modpath.."/teleport_tube.lua") end
if pipeworks.enable_pipe_devices then pdofile(pipeworks.modpath.."/devices.lua") end
2019-12-14 17:47:31 +01:00
if pipeworks.enable_redefines then
2021-04-27 12:16:40 +02:00
pdofile(pipeworks.modpath.."/compat-chests.lua")
pdofile(pipeworks.modpath.."/compat-furnaces.lua")
2019-12-14 17:47:31 +01:00
end
2021-04-27 12:16:40 +02:00
if pipeworks.enable_autocrafter then pdofile(pipeworks.modpath.."/autocrafter.lua") end
2019-12-14 17:47:31 +01:00
if pipeworks.enable_lua_tube and
(minetest.get_modpath("mesecons") or minetest.get_modpath("digilines")) then
2021-04-27 12:16:40 +02:00
pdofile(pipeworks.modpath.."/lua_tube.lua")
2019-12-14 17:47:31 +01:00
end
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
print("Pipeworks loaded!")