commit | author | age
|
ee5c6c
|
1 |
-- LV Alloy furnace |
5d799e
|
2 |
minetest.register_craft({ |
R |
3 |
output = 'technic:coal_alloy_furnace', |
82cba9
|
4 |
recipe = { |
5d799e
|
5 |
{'default:brick', 'default:brick', 'default:brick'}, |
ee5c6c
|
6 |
{'default:brick', '', 'default:brick'}, |
5d799e
|
7 |
{'default:brick', 'default:brick', 'default:brick'}, |
R |
8 |
} |
|
9 |
}) |
82cba9
|
10 |
|
ee5c6c
|
11 |
-- FIXME: kpoppel: I'd like to introduce an induction heating element here... |
82cba9
|
12 |
minetest.register_craft({ |
R |
13 |
output = 'technic:alloy_furnace', |
|
14 |
recipe = { |
|
15 |
{'default:brick', 'default:brick', 'default:brick'}, |
|
16 |
{'default:brick', '', 'default:brick'}, |
|
17 |
{'default:steel_ingot', 'moreores:copper_ingot', 'default:steel_ingot'}, |
|
18 |
} |
|
19 |
}) |
|
20 |
|
ee5c6c
|
21 |
local alloy_furnace_formspec = |
K |
22 |
"invsize[8,9;]".. |
|
23 |
"list[current_name;src;3,1;1,1;]".. |
|
24 |
"list[current_name;src2;3,2;1,1;]".. |
|
25 |
"list[current_name;dst;5,1;2,2;]".. |
|
26 |
"list[current_player;main;0,5;8,4;]".. |
|
27 |
"label[0,0;Electric Alloy Furnace]" |
82cba9
|
28 |
|
ee5c6c
|
29 |
minetest.register_node( |
K |
30 |
"technic:alloy_furnace", |
|
31 |
{ |
|
32 |
description = "Electric alloy furnace", |
|
33 |
tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", |
|
34 |
"technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front.png"}, |
|
35 |
paramtype2 = "facedir", |
|
36 |
groups = {cracky=2}, |
|
37 |
legacy_facedir_simple = true, |
|
38 |
sounds = default.node_sound_stone_defaults(), |
|
39 |
on_construct = function(pos) |
|
40 |
local meta = minetest.env:get_meta(pos) |
|
41 |
meta:set_string("infotext", "Electric Alloy furnace") |
|
42 |
meta:set_float("technic_power_machine", 1) |
|
43 |
meta:set_string("formspec", alloy_furnace_formspec) |
|
44 |
local inv = meta:get_inventory() |
|
45 |
inv:set_size("src", 1) |
|
46 |
inv:set_size("src2", 1) |
|
47 |
inv:set_size("dst", 4) |
|
48 |
end, |
|
49 |
can_dig = function(pos,player) |
|
50 |
local meta = minetest.env:get_meta(pos); |
|
51 |
local inv = meta:get_inventory() |
|
52 |
if not inv:is_empty("src") or not inv:is_empty("src2") or not inv:is_empty("dst") then |
|
53 |
minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); |
|
54 |
return false |
|
55 |
else |
|
56 |
return true |
|
57 |
end |
|
58 |
end, |
82cba9
|
59 |
}) |
R |
60 |
|
ee5c6c
|
61 |
minetest.register_node( |
K |
62 |
"technic:alloy_furnace_active", |
|
63 |
{ |
|
64 |
description = "Alloy Furnace", |
|
65 |
tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", |
|
66 |
"technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front_active.png"}, |
|
67 |
paramtype2 = "facedir", |
|
68 |
light_source = 8, |
|
69 |
drop = "technic:alloy_furnace", |
|
70 |
groups = {cracky=2,not_in_creative_inventory=1}, |
|
71 |
legacy_facedir_simple = true, |
|
72 |
sounds = default.node_sound_stone_defaults(), |
|
73 |
can_dig = function(pos,player) |
|
74 |
local meta = minetest.env:get_meta(pos); |
|
75 |
local inv = meta:get_inventory() |
|
76 |
if not inv:is_empty("src") or not inv:is_empty("src2") or not inv:is_empty("dst") then |
|
77 |
minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); |
|
78 |
return false |
|
79 |
else |
|
80 |
return true |
|
81 |
end |
|
82 |
end, |
|
83 |
}) |
82cba9
|
84 |
|
ee5c6c
|
85 |
minetest.register_abm( |
K |
86 |
{ nodenames = {"technic:alloy_furnace","technic:alloy_furnace_active"}, |
|
87 |
interval = 1, |
|
88 |
chance = 1, |
|
89 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
90 |
local meta = minetest.env:get_meta(pos) |
|
91 |
local eu_input = meta:get_int("LV_EU_input") |
|
92 |
local state = meta:get_int("state") |
|
93 |
local next_state = state |
82cba9
|
94 |
|
ee5c6c
|
95 |
-- Machine information |
K |
96 |
local machine_name = "Electric Alloy Furnace" |
|
97 |
local machine_node = "technic:alloy_furnace" |
|
98 |
local machine_state_demand = { 50, 600 } |
82cba9
|
99 |
|
ee5c6c
|
100 |
-- Setup meta data if it does not exist. state is used as an indicator of this |
K |
101 |
if state == 0 then |
|
102 |
meta:set_int("state", 1) |
|
103 |
meta:set_int("LV_EU_demand", machine_state_demand[1]) |
|
104 |
meta:set_int("LV_EU_input", 0) |
|
105 |
meta:set_int("tube_time", 0) |
|
106 |
return |
|
107 |
end |
|
108 |
|
|
109 |
-- Power off automatically if no longer connected to a switching station |
|
110 |
technic.switching_station_timeout_count(pos, "LV") |
|
111 |
|
|
112 |
-- State machine |
|
113 |
if eu_input == 0 then |
|
114 |
-- Unpowered - go idle |
|
115 |
hacky_swap_node(pos, machine_node) |
|
116 |
meta:set_string("infotext", machine_name.." Unpowered") |
|
117 |
next_state = 1 |
|
118 |
elseif eu_input == machine_state_demand[state] then |
|
119 |
-- Powered - do the state specific actions |
|
120 |
|
|
121 |
-- Execute always if powered logic |
|
122 |
local inv = meta:get_inventory() |
|
123 |
local empty = 1 |
|
124 |
local recipe = nil |
|
125 |
local result = nil |
5d799e
|
126 |
|
ee5c6c
|
127 |
-- Get what to cook if anything |
K |
128 |
local srcstack = inv:get_stack("src", 1) |
|
129 |
local src2stack = inv:get_stack("src2", 1) |
|
130 |
local src_item1 = nil |
|
131 |
local src_item2 = nil |
|
132 |
if srcstack and src2stack then |
|
133 |
src_item1 = srcstack:to_table() |
|
134 |
src_item2 = src2stack:to_table() |
|
135 |
empty = 0 |
|
136 |
end |
|
137 |
|
|
138 |
if src_item1 and src_item2 then |
|
139 |
recipe = technic.get_alloy_recipe(src_item1,src_item2) |
|
140 |
end |
|
141 |
if recipe then |
|
142 |
result = { name=recipe.dst_name, count=recipe.dst_count} |
|
143 |
end |
5d799e
|
144 |
|
ee5c6c
|
145 |
if recipe then |
K |
146 |
print("recipe "..recipe.dst_name.." : result "..result.name.." : empty "..empty.." : src_item1 "..src_item1.name.." : src_item2 "..src_item2.name) |
|
147 |
end |
5d799e
|
148 |
|
ee5c6c
|
149 |
if state == 1 then |
K |
150 |
hacky_swap_node(pos, machine_node) |
|
151 |
meta:set_string("infotext", machine_name.." Idle") |
|
152 |
|
|
153 |
if empty == 0 and recipe and inv:room_for_item("dst", result) then |
|
154 |
meta:set_string("infotext", machine_name.." Active") |
|
155 |
meta:set_string("src_time", 0) |
|
156 |
next_state = 2 |
|
157 |
end |
82cba9
|
158 |
|
ee5c6c
|
159 |
elseif state == 2 then |
K |
160 |
hacky_swap_node(pos, machine_node.."_active") |
|
161 |
meta:set_int("src_time", meta:get_int("src_time") + 1) |
|
162 |
if meta:get_int("src_time") == 4 then -- 4 ticks per output |
|
163 |
meta:set_string("src_time", 0) |
|
164 |
-- check if there's room for output in "dst" list and that we have the materials |
|
165 |
if recipe and inv:room_for_item("dst", result) then |
|
166 |
-- Take stuff from "src" list |
|
167 |
srcstack:take_item(recipe.src1_count) |
|
168 |
inv:set_stack("src", 1, srcstack) |
|
169 |
src2stack:take_item(recipe.src2_count) |
|
170 |
inv:set_stack("src2", 1, src2stack) |
|
171 |
-- Put result in "dst" list |
|
172 |
inv:add_item("dst",result) |
|
173 |
else |
|
174 |
next_state = 1 |
|
175 |
end |
|
176 |
end |
|
177 |
end |
|
178 |
-- Change state? |
|
179 |
if next_state ~= state then |
|
180 |
meta:set_int("LV_EU_demand", machine_state_demand[next_state]) |
|
181 |
meta:set_int("state", next_state) |
|
182 |
end |
|
183 |
end |
|
184 |
end, |
|
185 |
}) |
5d799e
|
186 |
|
ee5c6c
|
187 |
technic.register_LV_machine ("technic:alloy_furnace","RE") |
K |
188 |
technic.register_LV_machine ("technic:alloy_furnace_active","RE") |
5d799e
|
189 |
|
ee5c6c
|
190 |
-------------------------------------------------- |
K |
191 |
-- coal driven alloy furnace. This uses no EUs: |
|
192 |
-------------------------------------------------- |
82cba9
|
193 |
coal_alloy_furnace_formspec = |
R |
194 |
"size[8,9]".. |
|
195 |
"label[0,0;Alloy Furnace]".. |
|
196 |
"image[2,2;1,1;default_furnace_fire_bg.png]".. |
|
197 |
"list[current_name;fuel;2,3;1,1;]".. |
|
198 |
"list[current_name;src;2,1;1,1;]".. |
|
199 |
"list[current_name;src2;3,1;1,1;]".. |
|
200 |
"list[current_name;dst;5,1;2,2;]".. |
|
201 |
"list[current_player;main;0,5;8,4;]" |
ee5c6c
|
202 |
|
82cba9
|
203 |
minetest.register_node("technic:coal_alloy_furnace", { |
R |
204 |
description = "Alloy Furnace", |
|
205 |
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png", |
|
206 |
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front.png"}, |
|
207 |
paramtype2 = "facedir", |
|
208 |
groups = {cracky=2}, |
|
209 |
legacy_facedir_simple = true, |
|
210 |
sounds = default.node_sound_stone_defaults(), |
|
211 |
on_construct = function(pos) |
|
212 |
local meta = minetest.env:get_meta(pos) |
|
213 |
meta:set_string("formspec", coal_alloy_furnace_formspec) |
|
214 |
meta:set_string("infotext", "Alloy Furnace") |
|
215 |
local inv = meta:get_inventory() |
|
216 |
inv:set_size("fuel", 1) |
|
217 |
inv:set_size("src", 1) |
|
218 |
inv:set_size("src2", 1) |
|
219 |
inv:set_size("dst", 4) |
|
220 |
end, |
|
221 |
can_dig = function(pos,player) |
|
222 |
local meta = minetest.env:get_meta(pos); |
|
223 |
local inv = meta:get_inventory() |
|
224 |
if not (inv:is_empty("fuel") or inv:is_empty("dst") or inv:is_empty("src") or inv:is_empty("src2") )then |
|
225 |
return false |
|
226 |
end |
|
227 |
return true |
|
228 |
end, |
|
229 |
}) |
|
230 |
|
|
231 |
minetest.register_node("technic:coal_alloy_furnace_active", { |
|
232 |
description = "Alloy Furnace", |
|
233 |
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png", |
|
234 |
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front_active.png"}, |
|
235 |
paramtype2 = "facedir", |
|
236 |
light_source = 8, |
|
237 |
drop = "technic:coal_alloy_furnace", |
|
238 |
groups = {cracky=2, not_in_creative_inventory=1}, |
|
239 |
legacy_facedir_simple = true, |
|
240 |
sounds = default.node_sound_stone_defaults(), |
|
241 |
can_dig = function(pos,player) |
|
242 |
local meta = minetest.env:get_meta(pos); |
|
243 |
local inv = meta:get_inventory() |
|
244 |
if not (inv:is_empty("fuel") or inv:is_empty("dst") or inv:is_empty("src") or inv:is_empty("src2") )then |
|
245 |
return false |
|
246 |
end |
|
247 |
return true |
|
248 |
end, |
|
249 |
}) |
|
250 |
|
|
251 |
minetest.register_abm({ |
|
252 |
nodenames = {"technic:coal_alloy_furnace","technic:coal_alloy_furnace_active"}, |
|
253 |
interval = 1, |
|
254 |
chance = 1, |
ee5c6c
|
255 |
|
82cba9
|
256 |
action = function(pos, node, active_object_count, active_object_count_wider) |
R |
257 |
local meta = minetest.env:get_meta(pos) |
ee5c6c
|
258 |
for i, name in pairs({ |
82cba9
|
259 |
"fuel_totaltime", |
R |
260 |
"fuel_time", |
|
261 |
"src_totaltime", |
|
262 |
"src_time" |
|
263 |
}) do |
|
264 |
if meta:get_string(name) == "" then |
|
265 |
meta:set_float(name, 0.0) |
|
266 |
end |
|
267 |
end |
|
268 |
|
ee5c6c
|
269 |
local inv = meta:get_inventory() |
K |
270 |
local recipe = nil |
82cba9
|
271 |
|
ee5c6c
|
272 |
-- Get what to cook if anything |
K |
273 |
local srcstack = inv:get_stack("src", 1) |
|
274 |
if srcstack then src_item1=srcstack:to_table() end |
|
275 |
|
|
276 |
local src2stack = inv:get_stack("src2", 1) |
|
277 |
if src2stack then src_item2=src2stack:to_table() end |
|
278 |
|
|
279 |
if src_item1 and src_item2 then |
|
280 |
recipe = technic.get_alloy_recipe(src_item1,src_item2) |
|
281 |
end |
|
282 |
|
|
283 |
local was_active = false |
|
284 |
|
|
285 |
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then |
|
286 |
was_active = true |
|
287 |
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1) |
|
288 |
meta:set_float("src_time", meta:get_float("src_time") + 1) |
|
289 |
if recipe and meta:get_float("src_time") == 6 then |
|
290 |
-- check if there's room for output in "dst" list |
|
291 |
local dst_stack = { name=recipe.dst_name, count=recipe.dst_count} |
|
292 |
if inv:room_for_item("dst",dst_stack) then |
|
293 |
-- Take stuff from "src" list |
|
294 |
srcstack:take_item(recipe.src1_count) |
|
295 |
inv:set_stack("src", 1, srcstack) |
|
296 |
src2stack:take_item(recipe.src2_count) |
|
297 |
inv:set_stack("src2", 1, src2stack) |
|
298 |
-- Put result in "dst" list |
|
299 |
inv:add_item("dst",dst_stack) |
|
300 |
else |
|
301 |
print("Furnace inventory full!") -- Silly code... |
|
302 |
end |
|
303 |
meta:set_string("src_time", 0) |
|
304 |
end |
|
305 |
end |
|
306 |
|
|
307 |
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then |
|
308 |
local percent = math.floor(meta:get_float("fuel_time") / |
|
309 |
meta:get_float("fuel_totaltime") * 100) |
|
310 |
meta:set_string("infotext","Furnace active: "..percent.."%") |
|
311 |
hacky_swap_node(pos,"technic:coal_alloy_furnace_active") |
|
312 |
meta:set_string("formspec", |
|
313 |
"size[8,9]".. |
|
314 |
"label[0,0;Electric Alloy Furnace]".. |
|
315 |
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:".. |
|
316 |
(100-percent)..":default_furnace_fire_fg.png]".. |
|
317 |
"list[current_name;fuel;2,3;1,1;]".. |
|
318 |
"list[current_name;src;2,1;1,1;]".. |
|
319 |
"list[current_name;src2;3,1;1,1;]".. |
|
320 |
"list[current_name;dst;5,1;2,2;]".. |
|
321 |
"list[current_player;main;0,5;8,4;]") |
|
322 |
return |
|
323 |
end |
|
324 |
|
|
325 |
-- FIXME: Make this look more like the electrical version. |
|
326 |
-- This code refetches the recipe to see if it can be done again after the iteration |
82cba9
|
327 |
srcstack = inv:get_stack("src", 1) |
R |
328 |
if srcstack then src_item1=srcstack:to_table() end |
|
329 |
srcstack = inv:get_stack("src2", 1) |
|
330 |
if srcstack then src_item2=srcstack:to_table() end |
ee5c6c
|
331 |
if src_item1 and src_item2 then |
K |
332 |
recipe = technic.get_alloy_recipe(src_item1,src_item2) |
82cba9
|
333 |
end |
R |
334 |
|
ee5c6c
|
335 |
if recipe==nil then |
K |
336 |
if was_active then |
|
337 |
meta:set_string("infotext","Furnace is empty") |
|
338 |
hacky_swap_node(pos,"technic:coal_alloy_furnace") |
|
339 |
meta:set_string("formspec", coal_alloy_furnace_formspec) |
|
340 |
end |
|
341 |
return |
|
342 |
end |
|
343 |
|
|
344 |
-- Next take a hard look at the fuel situation |
82cba9
|
345 |
local fuel = nil |
R |
346 |
local fuellist = inv:get_list("fuel") |
|
347 |
|
|
348 |
if fuellist then |
ee5c6c
|
349 |
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) |
82cba9
|
350 |
end |
R |
351 |
|
|
352 |
if fuel.time <= 0 then |
ee5c6c
|
353 |
meta:set_string("infotext","Furnace out of fuel") |
K |
354 |
hacky_swap_node(pos,"technic:coal_alloy_furnace") |
|
355 |
meta:set_string("formspec", coal_alloy_furnace_formspec) |
|
356 |
return |
82cba9
|
357 |
end |
R |
358 |
|
|
359 |
meta:set_string("fuel_totaltime", fuel.time) |
|
360 |
meta:set_string("fuel_time", 0) |
ee5c6c
|
361 |
|
82cba9
|
362 |
local stack = inv:get_stack("fuel", 1) |
R |
363 |
stack:take_item() |
|
364 |
inv:set_stack("fuel", 1, stack) |
ee5c6c
|
365 |
end, |
K |
366 |
}) |