-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
330 lines (250 loc) · 7.04 KB
/
init.lua
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
local modpath = minetest.get_modpath("bitumen")
bitumen = {}
-- coal = 38
-- crude 44
bitumen.energy_density = {
tar = 20,
heavy_oil = 25,
light_oil = 30,
diesel = 36,
kerosene = 38,
gasoline = 34,
mineral_spirits = 42,
lpg = 45,
["bitumen:tar"] = 20,
["bitumen:heavy_oil"] = 25,
["bitumen:light_oil"] = 30,
["bitumen:diesel"] = 36,
["bitumen:kerosene"] = 38,
["bitumen:gasoline"] = 34,
["bitumen:mineral_spirits"] = 42,
["bitumen:lpg"] = 45,
}
-- a coal lump burns for 40 seconds
-- a bitumen:heat burns for 10 seconds
-- multiply the energy density by this factor to find the number of bitumen:heats
bitumen.coal_equivalency = .1
bitumen.fluid_to_heat = function(fluid, amount)
local d = bitumen.energy_density[fluid]
if d == nil then
return 0
end
return bitumen.coal_equivalency * d * amount
end
local function vmin(a, b)
return {
x = math.min(a.x, b.x),
y = math.min(a.y, b.y),
z = math.min(a.z, b.z),
}
end
local function vmax(a, b)
return {
x = math.max(a.x, b.x),
y = math.max(a.y, b.y),
z = math.max(a.z, b.z),
}
end
bitumen.check_foundation = function(p1, p2, accept)
local low = vmin(p1, p2)
local high = vmax(p1, p2)
--print(dump(low) .. "\n" .. dump(high))
for x = low.x, high.x do
for y = low.y, high.y do
for z = low.z, high.z do
local n = minetest.get_node({x=x, y=y, z=z})
if accept[n.name] == nil then
return false
end
end
end
end
return true
end
-- first initialize the internal APIs
dofile(modpath.."/craftitems.lua")
dofile(modpath.."/magic_nodes.lua")
dofile(modpath.."/blueprints.lua")
dofile(modpath.."/pipes.lua")
dofile(modpath.."/burner.lua")
dofile(modpath.."/pipeline.lua")
-- next core nodes
dofile(modpath.."/fluids.lua")
dofile(modpath.."/spills.lua")
dofile(modpath.."/concrete.lua")
dofile(modpath.."/vapors.lua")
-- now the kitchen sink
dofile(modpath.."/barrel.lua")
dofile(modpath.."/heater.lua")
dofile(modpath.."/pump.lua")
dofile(modpath.."/oilshale.lua")
dofile(modpath.."/wells.lua")
dofile(modpath.."/cylinder_tank.lua")
dofile(modpath.."/sphere_tank.lua")
dofile(modpath.."/refinery.lua")
dofile(modpath.."/lights.lua")
dofile(modpath.."/rock_crusher.lua")
-----------------------------------
-- --
-- * * * * * LOOK HERE * * * * * --
-- --
-----------------------------------
-- where players should look for information
dofile(modpath.."/crafts.lua")
dofile(modpath.."/ore_gen.lua")
-- completely unrelated experiments:
minetest.register_node("bitumen:glass", {
description = "Glass",
drawtype = "glasslike_framed_optional",
tiles = {"default_glass.png", "default_glass_detail.png"},
special_tiles = {"default_stone.png"},
paramtype = "light",
paramtype2 = "glasslikeliquidlevel",
--param2 = 30;
sunlight_propagates = true,
use_texture_alpha = true,
is_ground_content = false,
groups = {cracky = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_glass_defaults(),
on_construct = function(pos)
--local n = minetest.get_node(pos)
--n.param2 = 32
--minetest.set_node_level(pos, 32)
--minetest.swap_node(pos, {name = "bitumen:glass", param2 = 120})
end,
})
-- igore this; test for structure algorithm
local support = {}
minetest.register_abm({
nodenames = {"bitumen:glass"},
interval = 1,
chance = 1,
action = function(pos)
-- minetest.set_node_level(pos, 30)
local sides = {}
local on = minetest.get_node(pos)
local npos = {
{x=pos.x+1, y=pos.y, z=pos.z},
{x=pos.x-1, y=pos.y, z=pos.z},
{x=pos.x, y=pos.y, z=pos.z+1},
{x=pos.x, y=pos.y, z=pos.z-1},
}
pos.y = pos.y - 1
local ym = minetest.get_node(pos)
local sb = support[minetest.hash_node_position(pos)]
pos.y = pos.y + 1
local hash = minetest.hash_node_position(pos)
if ym.name == "air" then
local nb = {}
-- print("air below")
for _,p in ipairs(npos) do
local n = minetest.get_node(p)
nb[n.name] = (nb[n.name] or 0) + 1
end
if (nb["air"] or 0) == 4 then
support[hash] = nil
minetest.spawn_falling_node(pos, on)
return
end
if (nb["bitumen:glass"] or 0) > 0 then
for _,p in ipairs(npos) do
local s = support[minetest.hash_node_position(p)]
if s ~= nil then
print("found support: " .. s)
support[hash] = math.min(support[hash] or 999, s + 1)
end
end
end
if support[hash] == nil or support[hash] > 4 then
support[hash] = nil
minetest.spawn_falling_node(pos, on)
return
end
else
--print("setting support to 0")
support[hash] = sb or 0
end
--minetest.swap_node(pos, {name = "bitumen:glass", param2 = math.random(255)})
end
})
local function get_chest_formspec(pos)
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
local formspec =
"size[14,12]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[nodemeta:" .. spos .. ";main;0,0.3;14,7;]" ..
"list[current_player;main;3,7.85;8,1;]" ..
"list[current_player;main;3,9.08;8,3;8]" ..
"listring[nodemeta:" .. spos .. ";main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(3,7.85)
return formspec
end
minetest.register_node("bitumen:large_chest", {
description = "Large Chest",
drawtype = "nodebox",
tiles = {"default_chest_side.png"},
is_ground_content = false,
groups = {cracky = 2, oddly_breakable_by_hand = 3},
sounds = default.node_sound_glass_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("main", 14*7 )
meta:set_string("formspec", get_chest_formspec(pos))
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and
default.can_interact_with_node(player, pos)
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local name = stack:get_name()
local meta = minetest.get_meta(pos)
local minv = meta:get_inventory()
local pinv = player:get_inventory()
local sz = pinv:get_size("main")
for i = 1,sz do
local s = pinv:get_stack("main", i)
if s and s:get_name() == name then
local lo = minv:add_item("main", s)
if lo and lo:get_count() > 0 then
pinv:set_stack("main", i, lo)
break
else
pinv:set_stack("main", i, nil)
end
end
end
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
local name = stack:get_name()
local meta = minetest.get_meta(pos)
local minv = meta:get_inventory()
local pinv = player:get_inventory()
local sz = minv:get_size("main")
for i = 1,sz do
local s = minv:get_stack("main", i)
if s and s:get_name() == name then
local lo = pinv:add_item("main", s)
if lo and lo:get_count() > 0 then
minv:set_stack("main", i, lo)
break
else
minv:set_stack("main", i, nil)
end
end
end
end,
})
minetest.register_craft({
output = 'bitumen:large_chest',
recipe = {
{'group:wood', 'group:wood', 'group:wood'},
{'group:wood', 'default:chest', 'group:wood'},
{'group:wood', 'group:wood', 'group:wood'},
}
})