summaryrefslogtreecommitdiff
path: root/init.lua
blob: 106b471fe2a229ad19a375baa9668e23ffd5e709 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
-- 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.
--
-- License: WTFPL
--

-- Read (and if necessary, copy) the config file

local DEBUG = false

local worldpath = minetest.get_worldpath()
local modpath = minetest.get_modpath("pipeworks")

dofile(modpath.."/default_settings.txt")

if io.open(worldpath.."/pipeworks_settings.txt","r") == nil then

	io.input(modpath.."/default_settings.txt")
	io.output(worldpath.."/pipeworks_settings.txt")

	local size = 2^13      -- good buffer size (8K)
	while true do
		local block = io.read(size)
		if not block then
			io.close()
			break
		end
		io.write(block)
	end

else
	dofile(worldpath.."/pipeworks_settings.txt")
end

-- Helper functions

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

function pipeworks_fix_image_names(table, replacement)
	outtable={}
	for i in ipairs(table) do
		outtable[i]=string.gsub(table[i], "_XXXXX", replacement)
	end

	return outtable
end

function pipeworks_add_pipebox(t, b)
	for i in ipairs(b)
		do table.insert(t, b[i])
	end
end

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

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 parts of the mod

dofile(modpath.."/autoplace.lua")
dofile(modpath.."/item_transport.lua")
dofile(modpath.."/flowing_logic.lua")
dofile(modpath.."/crafts.lua")

dofile(modpath.."/tubes.lua")

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}}
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")

print("Pipeworks loaded!")