commit | author | age
|
ee0765
|
1 |
|
S |
2 |
-- Coal driven alloy furnace. This uses no EUs: |
|
3 |
|
be2f30
|
4 |
local S = technic.getter |
ee0765
|
5 |
|
S |
6 |
minetest.register_craft({ |
|
7 |
output = 'technic:coal_alloy_furnace', |
|
8 |
recipe = { |
|
9 |
{'default:brick', 'default:brick', 'default:brick'}, |
|
10 |
{'default:brick', '', 'default:brick'}, |
|
11 |
{'default:brick', 'default:brick', 'default:brick'}, |
|
12 |
} |
|
13 |
}) |
|
14 |
|
|
15 |
minetest.register_node("technic:coal_alloy_furnace", { |
be2f30
|
16 |
description = S("Coal Alloy Furnace"), |
0809dd
|
17 |
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", |
S |
18 |
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", |
|
19 |
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front.png"}, |
ee0765
|
20 |
paramtype2 = "facedir", |
S |
21 |
groups = {cracky=2}, |
|
22 |
legacy_facedir_simple = true, |
|
23 |
sounds = default.node_sound_stone_defaults(), |
|
24 |
on_construct = function(pos) |
|
25 |
local meta = minetest.env:get_meta(pos) |
|
26 |
meta:set_string("formspec", coal_alloy_furnace_formspec) |
be2f30
|
27 |
meta:set_string("infotext", S("Coal Alloy Furnace")) |
ee0765
|
28 |
local inv = meta:get_inventory() |
S |
29 |
inv:set_size("fuel", 1) |
|
30 |
inv:set_size("src", 1) |
|
31 |
inv:set_size("src2", 1) |
|
32 |
inv:set_size("dst", 4) |
|
33 |
end, |
0809dd
|
34 |
can_dig = technic.machine_can_dig, |
S |
35 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
36 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
37 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
ee0765
|
38 |
}) |
S |
39 |
|
|
40 |
minetest.register_node("technic:coal_alloy_furnace_active", { |
|
41 |
description = "Alloy Furnace", |
0809dd
|
42 |
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", |
S |
43 |
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", |
|
44 |
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front_active.png"}, |
ee0765
|
45 |
paramtype2 = "facedir", |
S |
46 |
light_source = 8, |
|
47 |
drop = "technic:coal_alloy_furnace", |
|
48 |
groups = {cracky=2, not_in_creative_inventory=1}, |
|
49 |
legacy_facedir_simple = true, |
|
50 |
sounds = default.node_sound_stone_defaults(), |
0809dd
|
51 |
can_dig = technic.machine_can_dig, |
S |
52 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
53 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
54 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
ee0765
|
55 |
}) |
S |
56 |
|
|
57 |
minetest.register_abm({ |
|
58 |
nodenames = {"technic:coal_alloy_furnace", "technic:coal_alloy_furnace_active"}, |
|
59 |
interval = 1, |
|
60 |
chance = 1, |
|
61 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
62 |
local meta = minetest.get_meta(pos) |
|
63 |
local inv = meta:get_inventory() |
|
64 |
local recipe = nil |
be2f30
|
65 |
local machine_name = S("Coal Alloy Furnace") |
ee0765
|
66 |
local formspec = |
S |
67 |
"size[8,9]".. |
be2f30
|
68 |
"label[0,0;"..machine_name.."]".. |
ee0765
|
69 |
"image[2,2;1,1;default_furnace_fire_bg.png]".. |
S |
70 |
"list[current_name;fuel;2,3;1,1;]".. |
|
71 |
"list[current_name;src;2,1;1,1;]".. |
|
72 |
"list[current_name;src2;3,1;1,1;]".. |
|
73 |
"list[current_name;dst;5,1;2,2;]".. |
|
74 |
"list[current_player;main;0,5;8,4;]" |
|
75 |
|
|
76 |
for i, name in pairs({ |
|
77 |
"fuel_totaltime", |
|
78 |
"fuel_time", |
|
79 |
"src_totaltime", |
|
80 |
"src_time"}) do |
|
81 |
if not meta:get_float(name) then |
|
82 |
meta:set_float(name, 0.0) |
|
83 |
end |
|
84 |
end |
|
85 |
|
|
86 |
-- Get what to cook if anything |
|
87 |
local srcstack = inv:get_stack("src", 1) |
|
88 |
local src2stack = inv:get_stack("src2", 1) |
|
89 |
local recipe = technic.get_alloy_recipe(srcstack, src2stack) |
|
90 |
if srcstack:get_name() > src2stack:get_name() then |
|
91 |
local temp = srcstack |
|
92 |
srcstack = src2stack |
|
93 |
src2stack = temp |
|
94 |
end |
|
95 |
|
|
96 |
local was_active = false |
|
97 |
|
|
98 |
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then |
|
99 |
was_active = true |
|
100 |
meta:set_int("fuel_time", meta:get_int("fuel_time") + 1) |
|
101 |
if recipe then |
|
102 |
meta:set_int("src_time", meta:get_int("src_time") + 1) |
|
103 |
if meta:get_int("src_time") == 6 then |
|
104 |
-- check if there's room for output in "dst" list |
|
105 |
local dst_stack = ItemStack(recipe.output) |
|
106 |
if inv:room_for_item("dst", dst_stack) then |
|
107 |
srcstack:take_item(recipe.input[1].count) |
|
108 |
inv:set_stack("src", 1, srcstack) |
|
109 |
src2stack:take_item(recipe.input[2].count) |
|
110 |
inv:set_stack("src2", 1, src2stack) |
|
111 |
inv:add_item("dst", dst_stack) |
|
112 |
end |
|
113 |
meta:set_int("src_time", 0) |
|
114 |
end |
|
115 |
else |
|
116 |
meta:set_int("src_time", 0) |
|
117 |
end |
|
118 |
end |
|
119 |
|
|
120 |
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then |
|
121 |
local percent = math.floor(meta:get_float("fuel_time") / |
|
122 |
meta:get_float("fuel_totaltime") * 100) |
be2f30
|
123 |
meta:set_string("infotext", S("%s Active"):format(machine_name).." ("..percent.."%)") |
f3d8b4
|
124 |
technic.swap_node(pos, "technic:coal_alloy_furnace_active") |
ee0765
|
125 |
meta:set_string("formspec", |
S |
126 |
"size[8,9]".. |
be2f30
|
127 |
"label[0,0;"..machine_name.."]".. |
ee0765
|
128 |
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:".. |
be2f30
|
129 |
(100 - percent)..":default_furnace_fire_fg.png]".. |
ee0765
|
130 |
"list[current_name;fuel;2,3;1,1;]".. |
S |
131 |
"list[current_name;src;2,1;1,1;]".. |
|
132 |
"list[current_name;src2;3,1;1,1;]".. |
|
133 |
"list[current_name;dst;5,1;2,2;]".. |
|
134 |
"list[current_player;main;0,5;8,4;]") |
|
135 |
return |
|
136 |
end |
|
137 |
|
|
138 |
-- FIXME: Make this look more like the electrical version. |
|
139 |
-- This code refetches the recipe to see if it can be done again after the iteration |
|
140 |
srcstack = inv:get_stack("src", 1) |
|
141 |
srcstack = inv:get_stack("src2", 1) |
|
142 |
local recipe = technic.get_alloy_recipe(srcstack, src2stack) |
|
143 |
|
|
144 |
if recipe then |
|
145 |
if was_active then |
|
146 |
meta:set_string("infotext", "Furnace is empty") |
f3d8b4
|
147 |
technic.swap_node(pos, "technic:coal_alloy_furnace") |
ee0765
|
148 |
meta:set_string("formspec", formspec) |
S |
149 |
end |
|
150 |
return |
|
151 |
end |
|
152 |
|
|
153 |
-- Next take a hard look at the fuel situation |
|
154 |
local fuel = nil |
|
155 |
local fuellist = inv:get_list("fuel") |
|
156 |
|
|
157 |
if fuellist then |
|
158 |
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) |
|
159 |
end |
|
160 |
|
|
161 |
if fuel.time <= 0 then |
be2f30
|
162 |
meta:set_string("infotext", S("%s Out Of Fuel"):format(machine_name)) |
f3d8b4
|
163 |
technic.swap_node(pos, "technic:coal_alloy_furnace") |
ee0765
|
164 |
meta:set_string("formspec", formspec) |
S |
165 |
return |
|
166 |
end |
|
167 |
|
|
168 |
meta:set_string("fuel_totaltime", fuel.time) |
|
169 |
meta:set_string("fuel_time", 0) |
|
170 |
|
|
171 |
local stack = inv:get_stack("fuel", 1) |
|
172 |
stack:take_item() |
|
173 |
inv:set_stack("fuel", 1, stack) |
|
174 |
end, |
|
175 |
}) |
|
176 |
|