forked from mt-mods/pipeworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcl_furnaces.lua
376 lines (322 loc) · 11.2 KB
/
mcl_furnaces.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
local old_furnace = table.copy(minetest.registered_nodes["mcl_furnaces:furnace"])
local old_blast_furnace = table.copy(minetest.registered_nodes["mcl_blast_furnace:blast_furnace"])
local old_smoker = table.copy(minetest.registered_nodes["mcl_smoker:smoker"])
local tube_entry = "^pipeworks_tube_connection_stony.png"
-- groups
local furnace_groups = old_furnace.groups
furnace_groups["tubedevice"] = 1
furnace_groups["tubedevice_receiver"] = 1
local furnace_groups_active = table.copy(furnace_groups)
furnace_groups_active["not_in_creative_inventory"] = 1
local blast_furnace_groups = old_blast_furnace.groups
blast_furnace_groups["tubedevice"] = 1
blast_furnace_groups["tubedevice_receiver"] = 1
local blast_furnace_groups_active = table.copy(blast_furnace_groups)
blast_furnace_groups_active["not_in_creative_inventory"] = 1
local smoker_groups = old_smoker.groups
smoker_groups["tubedevice"] = 1
smoker_groups["tubedevice_receiver"] = 1
local smoker_groups_active = table.copy(smoker_groups)
smoker_groups_active["not_in_creative_inventory"] = 1
-- a hack to give the exp to fake players it's be dropped instead added to (fake) player inv
local function give_xp(pos, player)
local meta = minetest.get_meta(pos)
local dir = vector.divide(minetest.facedir_to_dir(minetest.get_node(pos).param2), -1.95)
local xp = meta:get_int("xp")
if xp > 0 then
mcl_experience.throw_xp(vector.add(pos, dir), xp)
meta:set_int("xp", 0)
end
end
local override = {}
override.tiles = {
"default_furnace_top.png"..tube_entry,
"default_furnace_bottom.png"..tube_entry,
"default_furnace_side.png"..tube_entry,
"default_furnace_side.png"..tube_entry,
"default_furnace_side.png"..tube_entry,
"default_furnace_front.png"
}
override.groups = furnace_groups
override.tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1.0)
end
if direction.y == 1 then
return inv:add_item("fuel", stack)
else
return inv:add_item("src", stack)
end
end,
can_insert = function(pos,node,stack,direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if direction.y == 1 then
return inv:room_for_item("fuel", stack)
else
if meta:get_int("split_material_stacks") == 1 then
stack = stack:peek_item(1)
end
return inv:room_for_item("src", stack)
end
end,
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
}
override.after_place_node = function(pos, placer, itemstack, pointed_thing)
pipeworks.after_place(pos, placer, itemstack, pointed_thing)
end
override.after_dig_node = function(pos, oldnode, oldmetadata, digger)
old_furnace.after_dig_node(pos, oldnode, oldmetadata, digger)
pipeworks.after_dig(pos)
end
override.on_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname == "dst" then
if stack:get_name() == "mcl_core:iron_ingot" then
awards.unlock(player:get_player_name(), "mcl:acquireIron")
elseif stack:get_name() == "mcl_fishing:fish_cooked" then
awards.unlock(player:get_player_name(), "mcl:cookFish")
end
give_xp(pos, player)
end
end
override.on_rotate = pipeworks.on_rotate
local override_active = table.copy(override)
override_active.tiles = {
"default_furnace_top.png"..tube_entry,
"default_furnace_bottom.png"..tube_entry,
"default_furnace_side.png"..tube_entry,
"default_furnace_side.png"..tube_entry,
"default_furnace_side.png"..tube_entry,
"default_furnace_front_active.png",
}
override_active.groups = furnace_groups_active
override_active.tube = {
insert_object = function(pos,node,stack,direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1.0)
end
if direction.y == 1 then
return inv:add_item("fuel", stack)
else
return inv:add_item("src", stack)
end
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if direction.y == 1 then
return inv:room_for_item("fuel", stack)
else
return inv:room_for_item("src", stack)
end
end,
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
}
--blast furnace
local override_blast_furnace = {}
override_blast_furnace.tiles = {
"blast_furnace_top.png"..tube_entry,
"blast_furnace_top.png"..tube_entry,
"blast_furnace_side.png"..tube_entry,
"blast_furnace_side.png"..tube_entry,
"blast_furnace_side.png"..tube_entry,
"blast_furnace_front.png"
}
override_blast_furnace.groups = blast_furnace_groups
override_blast_furnace.tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1.0)
end
if direction.y == 1 then
return inv:add_item("fuel", stack)
else
return inv:add_item("src", stack)
end
end,
can_insert = function(pos,node,stack,direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if direction.y == 1 then
return inv:room_for_item("fuel", stack)
else
if meta:get_int("split_material_stacks") == 1 then
stack = stack:peek_item(1)
end
return inv:room_for_item("src", stack)
end
end,
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
}
override_blast_furnace.after_place_node = function(pos, placer, itemstack, pointed_thing)
pipeworks.after_place(pos, placer, itemstack, pointed_thing)
end
override_blast_furnace.after_dig_node = function(pos, oldnode, oldmetadata, digger)
old_blast_furnace.after_dig_node(pos, oldnode, oldmetadata, digger)
pipeworks.after_dig(pos)
end
override_blast_furnace.on_metadata_inventory_take = function(pos, listname, index, stack, player)
-- Award smelting achievements
if listname == "dst" then
if stack:get_name() == "mcl_core:iron_ingot" then
awards.unlock(player:get_player_name(), "mcl:acquireIron")
end
give_xp(pos, player)
end
end
override_blast_furnace.on_rotate = pipeworks.on_rotate
local override_blast_active = table.copy(override)
override_blast_active.tiles = {
"blast_furnace_top.png"..tube_entry,
"blast_furnace_top.png"..tube_entry,
"blast_furnace_side.png"..tube_entry,
"blast_furnace_side.png"..tube_entry,
"blast_furnace_side.png"..tube_entry,
{
name = "blast_furnace_front_on.png",
animation = { type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 48 }
},
}
override_blast_active.groups = blast_furnace_groups_active
override_blast_active.tube = {
insert_object = function(pos,node,stack,direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1.0)
end
if direction.y == 1 then
return inv:add_item("fuel", stack)
else
return inv:add_item("src", stack)
end
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if direction.y == 1 then
return inv:room_for_item("fuel", stack)
else
return inv:room_for_item("src", stack)
end
end,
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
}
-- smoker
local override_smoker = {}
override_smoker.tiles = {
"smoker_top.png"..tube_entry,
"smoker_bottom.png"..tube_entry,
"smoker_side.png"..tube_entry,
"smoker_side.png"..tube_entry,
"smoker_side.png"..tube_entry,
"smoker_front.png"
}
override_smoker.groups = smoker_groups
override_smoker.tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1.0)
end
if direction.y == 1 then
return inv:add_item("fuel", stack)
else
return inv:add_item("src", stack)
end
end,
can_insert = function(pos,node,stack,direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if direction.y == 1 then
return inv:room_for_item("fuel", stack)
else
if meta:get_int("split_material_stacks") == 1 then
stack = stack:peek_item(1)
end
return inv:room_for_item("src", stack)
end
end,
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
}
override_smoker.after_place_node = function(pos, placer, itemstack, pointed_thing)
pipeworks.after_place(pos, placer, itemstack, pointed_thing)
end
override_smoker.after_dig_node = function(pos, oldnode, oldmetadata, digger)
old_smoker.after_dig_node(pos, oldnode, oldmetadata, digger)
pipeworks.after_dig(pos)
end
override_smoker.on_metadata_inventory_take = function(pos, listname, index, stack, player)
-- Award fish achievements
if listname == "dst" then
if stack:get_name() == "mcl_fishing:fish_cooked" then
awards.unlock(player:get_player_name(), "mcl:cookFish")
end
give_xp(pos, player)
end
end
override_smoker.on_rotate = pipeworks.on_rotate
local override_smoker_active = table.copy(override)
override_smoker_active.tiles = {
"smoker_top.png"..tube_entry,
"smoker_bottom.png"..tube_entry,
"smoker_side.png"..tube_entry,
"smoker_side.png"..tube_entry,
"smoker_side.png"..tube_entry,
{
name = "smoker_front_on.png",
animation = { type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 48 }
},
}
override_smoker_active.groups = smoker_groups_active
override_smoker_active.tube = {
insert_object = function(pos,node,stack,direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1.0)
end
if direction.y == 1 then
return inv:add_item("fuel", stack)
else
return inv:add_item("src", stack)
end
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if direction.y == 1 then
return inv:room_for_item("fuel", stack)
else
return inv:room_for_item("src", stack)
end
end,
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
}
-- override
minetest.override_item("mcl_furnaces:furnace", override)
minetest.override_item("mcl_furnaces:furnace_active", override_active)
minetest.override_item("mcl_blast_furnace:blast_furnace", override_blast_furnace)
minetest.override_item("mcl_blast_furnace:blast_furnace_active", override_blast_active)
minetest.override_item("mcl_smoker:smoker", override_smoker)
minetest.override_item("mcl_smoker:smoker_active", override_smoker_active)