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