-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcommon.lua
More file actions
218 lines (191 loc) · 5.42 KB
/
Copy pathcommon.lua
File metadata and controls
218 lines (191 loc) · 5.42 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
-- Random variables
pipeworks.expect_infinite_stacks = true
if core.get_modpath("unified_inventory") or not core.settings:get_bool("creative_mode") then
pipeworks.expect_infinite_stacks = false
end
pipeworks.meseadjlist = {
vector.new( 0, 0, 1),
vector.new( 0, 0,-1),
vector.new( 0, 1, 0),
vector.new( 0,-1, 0),
vector.new( 1, 0, 0),
vector.new(-1, 0, 0),
}
pipeworks.rules_all = {
vector.new( 0, 0, 1),
vector.new( 0, 0,-1),
vector.new( 1, 0, 0),
vector.new(-1, 0, 0),
vector.new( 0, 1, 1),
vector.new( 0, 1,-1),
vector.new( 1, 1, 0),
vector.new(-1, 1, 0),
vector.new( 0,-1, 1),
vector.new( 0,-1,-1),
vector.new( 1,-1, 0),
vector.new(-1,-1, 0),
vector.new( 0, 1, 0),
vector.new( 0,-1, 0),
}
pipeworks.mesecons_rules = {
vector.new( 0, 0, 1),
vector.new( 0, 0,-1),
vector.new( 1, 0, 0),
vector.new(-1, 0, 0),
vector.new( 0, 1, 0),
vector.new( 0,-1, 0),
}
local digilines_enabled = core.get_modpath("digilines") ~= nil
if digilines_enabled and pipeworks.enable_vertical_digilines_connectivity then
pipeworks.digilines_rules=digilines.rules.default
else
-- These rules break vertical connectivity to deployers, node breakers, dispensers, and digiline filter injectors
-- via digiline conducting tubes. Changing them may break some builds on some servers, so the setting was added
-- for server admins to be able to revert to the old "broken" behavior as some builds may use it as a "feature".
-- See https://github.com/mt-mods/pipeworks/issues/64
pipeworks.digilines_rules = {
vector.new( 0, 0, 1),
vector.new( 0, 0,-1),
vector.new( 1, 0, 0),
vector.new(-1, 0, 0),
vector.new( 0, 1, 0),
vector.new( 0,-1, 0),
}
end
pipeworks.liquid_texture = core.registered_nodes[pipeworks.liquids.water.flowing].tiles[1]
if type(pipeworks.liquid_texture) == "table" then pipeworks.liquid_texture = pipeworks.liquid_texture.name end
-- 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
local function overlay_tube_texture(texture)
-- The texture appears the first time to be colorized as the opaque background.
return ("(%s)^[noalpha^[colorize:#dadada^(%s)"):format(texture, texture)
end
function pipeworks.make_tube_tile(tile)
if pipeworks.use_real_entities then
return tile
elseif type(tile) == "string" then
return overlay_tube_texture(tile)
else
tile = table.copy(tile)
if tile.color then
-- Won't work 100% of the time, but good enough.
tile.name = tile.name .. "^[multiply:" .. core.colorspec_to_colorstring(tile.color)
tile.color = nil
end
tile.name = overlay_tube_texture(tile.name)
tile.backface_culling = nil -- The texture is opaque
return tile
end
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 = core.get_meta(pos)
local owner = meta:get_string("owner")
if owner ~= "" and owner == name then -- wielders and filters
return true
end
return not core.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
-----------------------
-- Facedir functions --
-----------------------
function pipeworks.facedir_to_top_dir(facedir)
return ({[0] = vector.new( 0, 1, 0),
vector.new( 0, 0, 1),
vector.new( 0, 0,-1),
vector.new( 1, 0, 0),
vector.new(-1, 0, 0),
vector.new( 0,-1, 0)})
[math.floor(facedir / 4)]
end
function pipeworks.facedir_to_right_dir(facedir)
return vector.cross(
pipeworks.facedir_to_top_dir(facedir),
core.facedir_to_dir(facedir)
)
end
local directions = {}
pipeworks.directions = directions
function directions.side_to_dir(side)
return ({[0] = vector.new(),
vector.new( 0, 1, 0),
vector.new( 0, -1, 0),
vector.new( 1, 0, 0),
vector.new(-1, 0, 0),
vector.new( 0, 0, 1),
vector.new( 0, 0, -1)
})[side]
end
function directions.dir_to_side(dir)
local c = vector.dot(dir, vector.new(1, 2, 3)) + 4
return ({6, 2, 4, 0, 3, 1, 5})[c]
end
---------------------
-- Table functions --
---------------------
function pipeworks.table_contains(tbl, element)
for _, elt in pairs(tbl) do
if elt == element then
return true
end
end
return false
end
function pipeworks.table_extend(tbl, tbl2)
local oldlength = #tbl
for i = 1,#tbl2 do
tbl[oldlength + i] = tbl2[i]
end
end
function pipeworks.table_recursive_replace(tbl, pattern, replace_with)
if type(tbl) == "table" then
local tbl2 = {}
for key, value in pairs(tbl) do
tbl2[key] = pipeworks.table_recursive_replace(value, pattern, replace_with)
end
return tbl2
elseif type(tbl) == "string" then
return tbl:gsub(pattern, replace_with)
else
return tbl
end
end
---------
-- Env --
---------
function pipeworks.load_position(pos)
if pos.x < -30912 or pos.y < -30912 or pos.z < -30912 or
pos.x > 30927 or pos.y > 30927 or pos.z > 30927 then return end
if core.get_node_or_nil(pos) then
return
end
local vm = core.get_voxel_manip()
vm:read_from_map(pos, pos)
end
-- Kept for compatibility with old mods
pipeworks.create_fake_player = fakelib.create_player