2013-07-14 04:39:25 +02:00
|
|
|
-- Pipeworks mod by Vanessa Ezekowitz - 2013-07-13
|
2012-07-12 23:52:35 +02:00
|
|
|
--
|
2013-07-14 04:39:25 +02:00
|
|
|
-- This mod supplies various steel pipes and plastic pneumatic tubes
|
|
|
|
-- and devices that they can connect to.
|
2012-07-12 23:52:35 +02:00
|
|
|
--
|
|
|
|
-- License: WTFPL
|
|
|
|
--
|
|
|
|
|
2013-08-05 10:36:50 +02:00
|
|
|
-- Read (and if necessary, copy) the config file
|
2012-08-18 14:46:17 +02:00
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
local worldpath = minetest.get_worldpath()
|
|
|
|
local modpath = minetest.get_modpath("pipeworks")
|
2012-08-18 14:46:17 +02:00
|
|
|
|
2013-08-05 10:36:50 +02:00
|
|
|
dofile(modpath.."/default_settings.txt")
|
2012-08-18 14:46:17 +02:00
|
|
|
|
2013-08-05 10:36:50 +02:00
|
|
|
if io.open(worldpath.."/pipeworks_settings.txt","r") == nil then
|
2012-08-18 14:46:17 +02:00
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
io.input(modpath.."/default_settings.txt")
|
|
|
|
io.output(worldpath.."/pipeworks_settings.txt")
|
2012-08-18 14:46:17 +02:00
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
local size = 2^13 -- good buffer size (8K)
|
|
|
|
while true do
|
|
|
|
local block = io.read(size)
|
2013-08-05 10:36:50 +02:00
|
|
|
if not block then
|
|
|
|
io.close()
|
|
|
|
break
|
|
|
|
end
|
2013-07-14 04:39:25 +02:00
|
|
|
io.write(block)
|
|
|
|
end
|
2012-07-12 23:52:35 +02:00
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
else
|
|
|
|
dofile(worldpath.."/pipeworks_settings.txt")
|
|
|
|
end
|
2012-08-06 03:29:59 +02:00
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
-- Helper functions
|
2012-08-06 03:29:59 +02:00
|
|
|
|
2013-06-08 07:00:49 +02:00
|
|
|
if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
|
|
|
|
pipeworks_expect_infinite_stacks = false
|
|
|
|
else
|
|
|
|
pipeworks_expect_infinite_stacks = true
|
|
|
|
end
|
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
function pipeworks_fix_image_names(table, replacement)
|
2012-08-06 03:29:59 +02:00
|
|
|
outtable={}
|
2012-08-18 14:46:17 +02:00
|
|
|
for i in ipairs(table) do
|
|
|
|
outtable[i]=string.gsub(table[i], "_XXXXX", replacement)
|
2012-08-06 03:29:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return outtable
|
|
|
|
end
|
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
function pipeworks_add_pipebox(t, b)
|
2012-08-18 14:46:17 +02:00
|
|
|
for i in ipairs(b)
|
|
|
|
do table.insert(t, b[i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-08 07:00:49 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
elseif type(isprotect)=="function" then -- glomie's protection mod
|
|
|
|
if not isprotect(5, pos, placer) then
|
|
|
|
ownername = S("someone")
|
|
|
|
end
|
|
|
|
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 ownername ~= false then
|
|
|
|
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
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
|
2012-08-19 04:12:29 +02:00
|
|
|
end
|
2012-08-18 14:46:17 +02:00
|
|
|
end
|
2013-07-14 04:39:25 +02:00
|
|
|
return ntbl
|
2012-08-18 14:46:17 +02:00
|
|
|
end
|
|
|
|
|
2013-07-14 04:39:25 +02:00
|
|
|
-- Load the various parts of the mod
|
2013-06-22 23:51:57 +02:00
|
|
|
|
|
|
|
dofile(modpath.."/autoplace.lua")
|
|
|
|
dofile(modpath.."/item_transport.lua")
|
2013-07-14 04:39:25 +02:00
|
|
|
dofile(modpath.."/flowing_logic.lua")
|
|
|
|
dofile(modpath.."/crafts.lua")
|
|
|
|
|
|
|
|
dofile(modpath.."/tubes.lua")
|
|
|
|
|
|
|
|
if enable_pipes then dofile(modpath.."/pipes.lua") end
|
|
|
|
if enable_teleport_tube then dofile(modpath.."/teleport_tube.lua") end
|
|
|
|
if enable_pipe_devices then dofile(modpath.."/devices.lua") end
|
|
|
|
if enable_redefines then dofile(modpath.."/compat.lua") end
|
|
|
|
if enable_autocrafter then dofile(modpath.."/autocrafter.lua") end
|
|
|
|
if enable_deployer then dofile(modpath.."/deployer.lua") end
|
|
|
|
if enable_node_breaker then dofile(modpath.."/node_breaker.lua") end
|
|
|
|
|
|
|
|
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
|
|
|
|
local DEBUG = false
|
|
|
|
local CYCLIC = true
|
2013-02-01 00:49:47 +01:00
|
|
|
|
2012-08-06 03:29:59 +02:00
|
|
|
print("Pipeworks loaded!")
|