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