commit | author | age
|
be2f30
|
1 |
|
S |
2 |
local S = technic.getter |
|
3 |
|
c7a4c0
|
4 |
if unified_inventory and unified_inventory.register_craft_type then |
9b64ff
|
5 |
unified_inventory.register_craft_type("alloy", { |
Z |
6 |
description = S("Alloy cooking"), |
|
7 |
height = 2, |
|
8 |
width = 1, |
|
9 |
}) |
|
10 |
end |
|
11 |
|
ee0765
|
12 |
-- Register alloy recipes |
S |
13 |
technic.alloy_recipes = {} |
|
14 |
|
|
15 |
-- Register recipe in a table |
|
16 |
technic.register_alloy_recipe = function(metal1, count1, metal2, count2, result, count3) |
5cf765
|
17 |
local in1 = { |
ee0765
|
18 |
name = metal1, |
S |
19 |
count = count1, |
|
20 |
} |
5cf765
|
21 |
local in2 = { |
ee0765
|
22 |
name = metal2, |
S |
23 |
count = count2, |
|
24 |
} |
|
25 |
-- Sort the inputs alphebetically |
|
26 |
if in1.name > in2.name then |
|
27 |
local temp = in1 |
|
28 |
in1 = in2 |
|
29 |
in2 = temp |
|
30 |
end |
|
31 |
technic.alloy_recipes[in1.name.." "..in2.name] = { |
|
32 |
input = {in1, in2}, |
|
33 |
output = { |
|
34 |
name = result, |
|
35 |
count = count3, |
|
36 |
}, |
|
37 |
} |
|
38 |
if unified_inventory then |
|
39 |
unified_inventory.register_craft({ |
|
40 |
type = "alloy", |
|
41 |
output = result.." "..count3, |
|
42 |
items = {metal1.." "..count1, metal2.." "..count2}, |
9b64ff
|
43 |
width = 0, |
ee0765
|
44 |
}) |
S |
45 |
end |
|
46 |
end |
|
47 |
|
68b7bc
|
48 |
minetest.after(0.01, function () |
Z |
49 |
for _, recipe in pairs(technic.alloy_recipes) do |
|
50 |
local in1 = recipe.input[1] |
|
51 |
local in2 = recipe.input[2] |
|
52 |
local in1n = in1.name |
|
53 |
local in2n = in2.name |
|
54 |
while minetest.registered_aliases[in1n] do |
|
55 |
in1n = minetest.registered_aliases[in1n] |
|
56 |
end |
|
57 |
while minetest.registered_aliases[in2n] do |
|
58 |
in2n = minetest.registered_aliases[in2n] |
|
59 |
end |
|
60 |
if in1n > in2n then |
|
61 |
local temp = in1 |
|
62 |
in1 = in2 |
|
63 |
in2 = temp |
|
64 |
temp = in1n |
|
65 |
in1n = in2n |
|
66 |
in2n = temp |
|
67 |
end |
|
68 |
technic.alloy_recipes[in1n.." "..in2n] = { |
|
69 |
input = { |
|
70 |
{ name = in1n, count = in1.count }, |
|
71 |
{ name = in2n, count = in2.count }, |
|
72 |
}, |
|
73 |
output = recipe.output, |
|
74 |
} |
|
75 |
end |
|
76 |
end) |
|
77 |
|
ee0765
|
78 |
-- Retrieve a recipe given the input metals. |
S |
79 |
function technic.get_alloy_recipe(stack1, stack2) |
|
80 |
-- Sort the stacks alphebetically |
|
81 |
if stack1:get_name() > stack2:get_name() then |
|
82 |
local temp = stack1 |
|
83 |
stack1 = stack2 |
|
84 |
stack2 = temp |
|
85 |
end |
|
86 |
for _, recipe in pairs(technic.alloy_recipes) do |
|
87 |
if recipe.input[1].name == stack1:get_name() and |
|
88 |
recipe.input[2].name == stack2:get_name() and |
|
89 |
stack1:get_count() >= recipe.input[1].count and |
|
90 |
stack2:get_count() >= recipe.input[2].count then |
|
91 |
return recipe |
|
92 |
end |
|
93 |
end |
|
94 |
end |
|
95 |
|
|
96 |
technic.register_alloy_recipe("technic:copper_dust", 3, "technic:tin_dust", 1, "technic:bronze_dust", 4) |
|
97 |
technic.register_alloy_recipe("default:copper_ingot", 3, "moreores:tin_ingot", 1, "moreores:bronze_ingot", 4) |
68b7bc
|
98 |
technic.register_alloy_recipe("technic:wrought_iron_dust", 1, "technic:coal_dust", 1, "technic:carbon_steel_dust", 1) |
Z |
99 |
technic.register_alloy_recipe("technic:wrought_iron_ingot", 1, "technic:coal_dust", 1, "technic:carbon_steel_ingot", 1) |
|
100 |
technic.register_alloy_recipe("technic:carbon_steel_dust", 1, "technic:coal_dust", 1, "technic:cast_iron_dust", 1) |
|
101 |
technic.register_alloy_recipe("technic:carbon_steel_ingot", 1, "technic:coal_dust", 1, "technic:cast_iron_ingot", 1) |
|
102 |
technic.register_alloy_recipe("technic:carbon_steel_dust", 3, "technic:chromium_dust", 1, "technic:stainless_steel_dust", 4) |
|
103 |
technic.register_alloy_recipe("technic:carbon_steel_ingot", 3, "technic:chromium_ingot", 1, "technic:stainless_steel_ingot", 4) |
ee0765
|
104 |
technic.register_alloy_recipe("technic:copper_dust", 2, "technic:zinc_dust", 1, "technic:brass_dust", 3) |
S |
105 |
technic.register_alloy_recipe("default:copper_ingot", 2, "technic:zinc_ingot", 1, "technic:brass_ingot", 3) |
|
106 |
technic.register_alloy_recipe("default:sand", 2, "technic:coal_dust", 2, "technic:silicon_wafer", 1) |
|
107 |
technic.register_alloy_recipe("technic:silicon_wafer", 1, "technic:gold_dust", 1, "technic:doped_silicon_wafer", 1) |
|
108 |
|
08db41
|
109 |
local tube = { |
S |
110 |
insert_object = function(pos, node, stack, direction) |
|
111 |
local meta = minetest.get_meta(pos) |
|
112 |
local inv = meta:get_inventory() |
|
113 |
return inv:add_item("src", stack) |
|
114 |
end, |
|
115 |
can_insert = function(pos, node, stack, direction) |
|
116 |
local meta = minetest.get_meta(pos) |
|
117 |
local inv = meta:get_inventory() |
|
118 |
return inv:room_for_item("src", stack) |
|
119 |
end, |
|
120 |
connect_sides = {left=1, right=1, back=1, top=1, bottom=1}, |
|
121 |
} |
|
122 |
|
ee0765
|
123 |
|
S |
124 |
function technic.register_alloy_furnace(data) |
|
125 |
local tier = data.tier |
|
126 |
local ltier = string.lower(tier) |
|
127 |
|
|
128 |
local tube_side_texture = data.tube and "technic_"..ltier.."_alloy_furnace_side_tube.png" |
|
129 |
or "technic_"..ltier.."_alloy_furnace_side.png" |
08db41
|
130 |
|
ee0765
|
131 |
local groups = {cracky=2} |
S |
132 |
local active_groups = {cracky=2, not_in_creative_inventory=1} |
|
133 |
if data.tube then |
|
134 |
groups.tubedevice = 1 |
|
135 |
groups.tubedevice_receiver = 1 |
|
136 |
active_groups.tubedevice = 1 |
|
137 |
active_groups.tubedevice_receiver = 1 |
|
138 |
end |
|
139 |
|
|
140 |
local formspec = |
|
141 |
"invsize[8,10;]".. |
be2f30
|
142 |
"label[0,0;"..S("%s Alloy Furnace"):format(tier).."]".. |
ee0765
|
143 |
"list[current_name;src;3,1;1,2;]".. |
S |
144 |
"list[current_name;dst;5,1;2,2;]".. |
|
145 |
"list[current_player;main;0,6;8,4;]" |
|
146 |
if data.upgrade then |
|
147 |
formspec = formspec.. |
|
148 |
"list[current_name;upgrade1;1,4;1,1;]".. |
|
149 |
"list[current_name;upgrade2;2,4;1,1;]".. |
39c41a
|
150 |
"label[1,5;"..S("Upgrade Slots").."]" |
ee0765
|
151 |
end |
S |
152 |
|
|
153 |
minetest.register_node("technic:"..ltier.."_alloy_furnace", { |
be2f30
|
154 |
description = S("%s Alloy Furnace"):format(tier), |
ee0765
|
155 |
tiles = {"technic_"..ltier.."_alloy_furnace_top.png", |
S |
156 |
"technic_"..ltier.."_alloy_furnace_bottom.png", |
|
157 |
tube_side_texture, |
|
158 |
tube_side_texture, |
|
159 |
"technic_"..ltier.."_alloy_furnace_side.png", |
|
160 |
"technic_"..ltier.."_alloy_furnace_front.png"}, |
|
161 |
paramtype2 = "facedir", |
|
162 |
groups = groups, |
08db41
|
163 |
tube = data.tube and tube or nil, |
ee0765
|
164 |
legacy_facedir_simple = true, |
S |
165 |
sounds = default.node_sound_stone_defaults(), |
|
166 |
on_construct = function(pos) |
|
167 |
local meta = minetest.get_meta(pos) |
|
168 |
local name = minetest.get_node(pos).name |
|
169 |
|
76a8ac
|
170 |
meta:set_string("infotext", S("%s Alloy Furnace"):format(tier)) |
S |
171 |
meta:set_string("formspec", formspec) |
ee0765
|
172 |
meta:set_int("tube_time", 0) |
S |
173 |
local inv = meta:get_inventory() |
|
174 |
inv:set_size("src", 2) |
|
175 |
inv:set_size("dst", 4) |
|
176 |
inv:set_size("upgrade1", 1) |
|
177 |
inv:set_size("upgrade2", 1) |
|
178 |
end, |
0809dd
|
179 |
can_dig = technic.machine_can_dig, |
S |
180 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
181 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
182 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
ee0765
|
183 |
}) |
S |
184 |
|
|
185 |
minetest.register_node("technic:"..ltier.."_alloy_furnace_active",{ |
be2f30
|
186 |
description = S(tier.." Alloy Furnace"), |
ee0765
|
187 |
tiles = {"technic_"..ltier.."_alloy_furnace_top.png", |
S |
188 |
"technic_"..ltier.."_alloy_furnace_bottom.png", |
|
189 |
tube_side_texture, |
|
190 |
tube_side_texture, |
|
191 |
"technic_"..ltier.."_alloy_furnace_side.png", |
|
192 |
"technic_"..ltier.."_alloy_furnace_front_active.png"}, |
|
193 |
paramtype2 = "facedir", |
|
194 |
light_source = 8, |
|
195 |
drop = "technic:"..ltier.."_alloy_furnace", |
|
196 |
groups = active_groups, |
08db41
|
197 |
tube = data.tube and tube or nil, |
ee0765
|
198 |
legacy_facedir_simple = true, |
S |
199 |
sounds = default.node_sound_stone_defaults(), |
0809dd
|
200 |
can_dig = technic.machine_can_dig, |
S |
201 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
202 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
203 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
ee0765
|
204 |
}) |
S |
205 |
|
|
206 |
minetest.register_abm({ |
|
207 |
nodenames = {"technic:"..ltier.."_alloy_furnace", "technic:"..ltier.."_alloy_furnace_active"}, |
|
208 |
interval = 1, |
|
209 |
chance = 1, |
|
210 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
211 |
local meta = minetest.get_meta(pos) |
|
212 |
local inv = meta:get_inventory() |
76a8ac
|
213 |
local eu_input = meta:get_int(tier.."_EU_input") |
ee0765
|
214 |
|
S |
215 |
-- Machine information |
76a8ac
|
216 |
local machine_name = S("%s Alloy Furnace"):format(tier) |
S |
217 |
local machine_node = "technic:"..ltier.."_alloy_furnace" |
ee0765
|
218 |
local machine_demand = data.demand |
S |
219 |
|
|
220 |
-- Setup meta data if it does not exist. |
|
221 |
if not eu_input then |
76a8ac
|
222 |
meta:set_int(tier.."_EU_demand", machine_demand[1]) |
S |
223 |
meta:set_int(tier.."_EU_input", 0) |
ee0765
|
224 |
end |
S |
225 |
|
|
226 |
-- Power off automatically if no longer connected to a switching station |
76a8ac
|
227 |
technic.switching_station_timeout_count(pos, tier) |
ee0765
|
228 |
|
S |
229 |
local EU_upgrade, tube_upgrade = 0, 0 |
|
230 |
if data.upgrade then |
|
231 |
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta) |
|
232 |
end |
|
233 |
if data.tube then |
|
234 |
technic.handle_machine_pipeworks(pos, tube_upgrade) |
|
235 |
end |
|
236 |
|
|
237 |
-- Get what to cook if anything |
|
238 |
local srcstack = inv:get_stack("src", 1) |
|
239 |
local src2stack = inv:get_stack("src", 2) |
|
240 |
local recipe = technic.get_alloy_recipe(srcstack, src2stack) |
|
241 |
local result = recipe and ItemStack(recipe.output) or nil |
|
242 |
-- Sort the stacks alphabetically |
|
243 |
if srcstack:get_name() > src2stack:get_name() then |
|
244 |
local temp = srcstack |
|
245 |
srcstack = src2stack |
|
246 |
src2stack = temp |
|
247 |
end |
bd3cc7
|
248 |
if not result or |
S |
249 |
not inv:room_for_item("dst", result) then |
f3d8b4
|
250 |
technic.swap_node(pos, machine_node) |
be2f30
|
251 |
meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
76a8ac
|
252 |
meta:set_int(tier.."_EU_demand", 0) |
ee0765
|
253 |
return |
S |
254 |
end |
|
255 |
|
|
256 |
if eu_input < machine_demand[EU_upgrade+1] then |
|
257 |
-- Unpowered - go idle |
f3d8b4
|
258 |
technic.swap_node(pos, machine_node) |
be2f30
|
259 |
meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) |
ee0765
|
260 |
elseif eu_input >= machine_demand[EU_upgrade+1] then |
S |
261 |
-- Powered |
f3d8b4
|
262 |
technic.swap_node(pos, machine_node.."_active") |
be2f30
|
263 |
meta:set_string("infotext", S("%s Active"):format(machine_name)) |
ee0765
|
264 |
meta:set_int("src_time", meta:get_int("src_time") + 1) |
S |
265 |
if meta:get_int("src_time") == data.cook_time then |
|
266 |
meta:set_int("src_time", 0) |
|
267 |
-- check if there's room for output and that we have the materials |
|
268 |
if inv:room_for_item("dst", result) then |
|
269 |
srcstack:take_item(recipe.input[1].count) |
|
270 |
inv:set_stack("src", 1, srcstack) |
|
271 |
src2stack:take_item(recipe.input[2].count) |
|
272 |
inv:set_stack("src", 2, src2stack) |
|
273 |
-- Put result in "dst" list |
|
274 |
inv:add_item("dst", result) |
|
275 |
else |
|
276 |
next_state = 1 |
|
277 |
end |
|
278 |
end |
|
279 |
|
|
280 |
end |
76a8ac
|
281 |
meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
ee0765
|
282 |
end, |
S |
283 |
}) |
|
284 |
|
|
285 |
technic.register_machine(tier, "technic:"..ltier.."_alloy_furnace", technic.receiver) |
|
286 |
technic.register_machine(tier, "technic:"..ltier.."_alloy_furnace_active", technic.receiver) |
|
287 |
|
|
288 |
end -- End registration |
|
289 |
|