2013-10-30 18:45:32 +01:00
|
|
|
|
|
|
|
local S = technic.getter
|
|
|
|
|
2014-05-06 22:11:04 +02:00
|
|
|
if unified_inventory and unified_inventory.register_craft_type then
|
2014-04-30 01:19:17 +02:00
|
|
|
unified_inventory.register_craft_type("alloy", {
|
|
|
|
description = S("Alloy cooking"),
|
|
|
|
height = 2,
|
|
|
|
width = 1,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
-- Register alloy recipes
|
|
|
|
technic.alloy_recipes = {}
|
|
|
|
|
|
|
|
-- Register recipe in a table
|
|
|
|
technic.register_alloy_recipe = function(metal1, count1, metal2, count2, result, count3)
|
2013-12-17 19:56:37 +01:00
|
|
|
local in1 = {
|
2013-07-17 21:34:35 +02:00
|
|
|
name = metal1,
|
|
|
|
count = count1,
|
|
|
|
}
|
2013-12-17 19:56:37 +01:00
|
|
|
local in2 = {
|
2013-07-17 21:34:35 +02:00
|
|
|
name = metal2,
|
|
|
|
count = count2,
|
|
|
|
}
|
|
|
|
-- Sort the inputs alphebetically
|
|
|
|
if in1.name > in2.name then
|
|
|
|
local temp = in1
|
|
|
|
in1 = in2
|
|
|
|
in2 = temp
|
|
|
|
end
|
|
|
|
technic.alloy_recipes[in1.name.." "..in2.name] = {
|
|
|
|
input = {in1, in2},
|
|
|
|
output = {
|
|
|
|
name = result,
|
|
|
|
count = count3,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if unified_inventory then
|
|
|
|
unified_inventory.register_craft({
|
|
|
|
type = "alloy",
|
|
|
|
output = result.." "..count3,
|
|
|
|
items = {metal1.." "..count1, metal2.." "..count2},
|
2014-04-30 01:19:17 +02:00
|
|
|
width = 0,
|
2013-07-17 21:34:35 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
split default iron/steel into three metals
Override the default mod's iron/steel substance, replacing it with three
metals: wrought iron (pure iron), carbon steel (iron alloyed with a little
carbon), and cast iron (iron alloyed with lots of carbon). Wrought iron
is easiest to refine, then cast iron, and carbon steel the most difficult,
matching the historical progression. Recipes that used default steel are
changed to use one of the three, the choice of alloy for each application
being both somewhat realistic and also matching up with game progression.
The default:steel{_ingot,block} items are identified specifically with
wrought iron. This makes the default refining recipes work appropriately.
Iron-using recipes defined outside technic are thus necessarily
reinterpreted to use wrought iron, which is mostly appropriate.
Some objects are renamed accordingly.
Rather than use the default steel textures for wrought iron, with technic
providing textures for the other two, technic now provides textures for
all three metals. This avoids problems that would occur with texture
packs that provide default_steel_{ingot,block} textures that are not
intended to support this wrought-iron/carbon-steel/cast-iron distinction.
A texture pack can provide a distinct set of three textures specifically
for the situation where this distinction is required.
Incidentally make grinding and alloy cooking recipes work correctly when
ingredients are specified by alias.
2014-05-16 23:02:49 +02:00
|
|
|
minetest.after(0.01, function ()
|
|
|
|
for _, recipe in pairs(technic.alloy_recipes) do
|
|
|
|
local in1 = recipe.input[1]
|
|
|
|
local in2 = recipe.input[2]
|
|
|
|
local in1n = in1.name
|
|
|
|
local in2n = in2.name
|
|
|
|
while minetest.registered_aliases[in1n] do
|
|
|
|
in1n = minetest.registered_aliases[in1n]
|
|
|
|
end
|
|
|
|
while minetest.registered_aliases[in2n] do
|
|
|
|
in2n = minetest.registered_aliases[in2n]
|
|
|
|
end
|
|
|
|
if in1n > in2n then
|
|
|
|
local temp = in1
|
|
|
|
in1 = in2
|
|
|
|
in2 = temp
|
|
|
|
temp = in1n
|
|
|
|
in1n = in2n
|
|
|
|
in2n = temp
|
|
|
|
end
|
|
|
|
technic.alloy_recipes[in1n.." "..in2n] = {
|
|
|
|
input = {
|
|
|
|
{ name = in1n, count = in1.count },
|
|
|
|
{ name = in2n, count = in2.count },
|
|
|
|
},
|
|
|
|
output = recipe.output,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
-- Retrieve a recipe given the input metals.
|
|
|
|
function technic.get_alloy_recipe(stack1, stack2)
|
|
|
|
-- Sort the stacks alphebetically
|
|
|
|
if stack1:get_name() > stack2:get_name() then
|
|
|
|
local temp = stack1
|
|
|
|
stack1 = stack2
|
|
|
|
stack2 = temp
|
|
|
|
end
|
|
|
|
for _, recipe in pairs(technic.alloy_recipes) do
|
|
|
|
if recipe.input[1].name == stack1:get_name() and
|
|
|
|
recipe.input[2].name == stack2:get_name() and
|
|
|
|
stack1:get_count() >= recipe.input[1].count and
|
|
|
|
stack2:get_count() >= recipe.input[2].count then
|
|
|
|
return recipe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
technic.register_alloy_recipe("technic:copper_dust", 3, "technic:tin_dust", 1, "technic:bronze_dust", 4)
|
|
|
|
technic.register_alloy_recipe("default:copper_ingot", 3, "moreores:tin_ingot", 1, "moreores:bronze_ingot", 4)
|
split default iron/steel into three metals
Override the default mod's iron/steel substance, replacing it with three
metals: wrought iron (pure iron), carbon steel (iron alloyed with a little
carbon), and cast iron (iron alloyed with lots of carbon). Wrought iron
is easiest to refine, then cast iron, and carbon steel the most difficult,
matching the historical progression. Recipes that used default steel are
changed to use one of the three, the choice of alloy for each application
being both somewhat realistic and also matching up with game progression.
The default:steel{_ingot,block} items are identified specifically with
wrought iron. This makes the default refining recipes work appropriately.
Iron-using recipes defined outside technic are thus necessarily
reinterpreted to use wrought iron, which is mostly appropriate.
Some objects are renamed accordingly.
Rather than use the default steel textures for wrought iron, with technic
providing textures for the other two, technic now provides textures for
all three metals. This avoids problems that would occur with texture
packs that provide default_steel_{ingot,block} textures that are not
intended to support this wrought-iron/carbon-steel/cast-iron distinction.
A texture pack can provide a distinct set of three textures specifically
for the situation where this distinction is required.
Incidentally make grinding and alloy cooking recipes work correctly when
ingredients are specified by alias.
2014-05-16 23:02:49 +02:00
|
|
|
technic.register_alloy_recipe("technic:wrought_iron_dust", 1, "technic:coal_dust", 1, "technic:carbon_steel_dust", 1)
|
|
|
|
technic.register_alloy_recipe("technic:wrought_iron_ingot", 1, "technic:coal_dust", 1, "technic:carbon_steel_ingot", 1)
|
|
|
|
technic.register_alloy_recipe("technic:carbon_steel_dust", 1, "technic:coal_dust", 1, "technic:cast_iron_dust", 1)
|
|
|
|
technic.register_alloy_recipe("technic:carbon_steel_ingot", 1, "technic:coal_dust", 1, "technic:cast_iron_ingot", 1)
|
|
|
|
technic.register_alloy_recipe("technic:carbon_steel_dust", 3, "technic:chromium_dust", 1, "technic:stainless_steel_dust", 4)
|
|
|
|
technic.register_alloy_recipe("technic:carbon_steel_ingot", 3, "technic:chromium_ingot", 1, "technic:stainless_steel_ingot", 4)
|
2013-07-17 21:34:35 +02:00
|
|
|
technic.register_alloy_recipe("technic:copper_dust", 2, "technic:zinc_dust", 1, "technic:brass_dust", 3)
|
|
|
|
technic.register_alloy_recipe("default:copper_ingot", 2, "technic:zinc_ingot", 1, "technic:brass_ingot", 3)
|
|
|
|
technic.register_alloy_recipe("default:sand", 2, "technic:coal_dust", 2, "technic:silicon_wafer", 1)
|
|
|
|
technic.register_alloy_recipe("technic:silicon_wafer", 1, "technic:gold_dust", 1, "technic:doped_silicon_wafer", 1)
|
|
|
|
|
2013-11-26 22:33:27 +01:00
|
|
|
local tube = {
|
|
|
|
insert_object = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:add_item("src", stack)
|
|
|
|
end,
|
|
|
|
can_insert = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:room_for_item("src", stack)
|
|
|
|
end,
|
|
|
|
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
|
|
|
|
}
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
|
|
|
|
function technic.register_alloy_furnace(data)
|
|
|
|
local tier = data.tier
|
|
|
|
local ltier = string.lower(tier)
|
|
|
|
|
|
|
|
local tube_side_texture = data.tube and "technic_"..ltier.."_alloy_furnace_side_tube.png"
|
|
|
|
or "technic_"..ltier.."_alloy_furnace_side.png"
|
2013-11-26 22:33:27 +01:00
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
local groups = {cracky=2}
|
|
|
|
local active_groups = {cracky=2, not_in_creative_inventory=1}
|
|
|
|
if data.tube then
|
|
|
|
groups.tubedevice = 1
|
|
|
|
groups.tubedevice_receiver = 1
|
|
|
|
active_groups.tubedevice = 1
|
|
|
|
active_groups.tubedevice_receiver = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local formspec =
|
|
|
|
"invsize[8,10;]"..
|
2013-10-30 18:45:32 +01:00
|
|
|
"label[0,0;"..S("%s Alloy Furnace"):format(tier).."]"..
|
2013-07-17 21:34:35 +02:00
|
|
|
"list[current_name;src;3,1;1,2;]"..
|
|
|
|
"list[current_name;dst;5,1;2,2;]"..
|
|
|
|
"list[current_player;main;0,6;8,4;]"
|
|
|
|
if data.upgrade then
|
|
|
|
formspec = formspec..
|
|
|
|
"list[current_name;upgrade1;1,4;1,1;]"..
|
|
|
|
"list[current_name;upgrade2;2,4;1,1;]"..
|
2014-04-16 19:10:00 +02:00
|
|
|
"label[1,5;"..S("Upgrade Slots").."]"
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("technic:"..ltier.."_alloy_furnace", {
|
2013-10-30 18:45:32 +01:00
|
|
|
description = S("%s Alloy Furnace"):format(tier),
|
2013-07-17 21:34:35 +02:00
|
|
|
tiles = {"technic_"..ltier.."_alloy_furnace_top.png",
|
|
|
|
"technic_"..ltier.."_alloy_furnace_bottom.png",
|
|
|
|
tube_side_texture,
|
|
|
|
tube_side_texture,
|
|
|
|
"technic_"..ltier.."_alloy_furnace_side.png",
|
|
|
|
"technic_"..ltier.."_alloy_furnace_front.png"},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = groups,
|
2013-11-26 22:33:27 +01:00
|
|
|
tube = data.tube and tube or nil,
|
2013-07-17 21:34:35 +02:00
|
|
|
legacy_facedir_simple = true,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local name = minetest.get_node(pos).name
|
|
|
|
|
2013-11-26 22:53:52 +01:00
|
|
|
meta:set_string("infotext", S("%s Alloy Furnace"):format(tier))
|
|
|
|
meta:set_string("formspec", formspec)
|
2013-07-17 21:34:35 +02:00
|
|
|
meta:set_int("tube_time", 0)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("src", 2)
|
|
|
|
inv:set_size("dst", 4)
|
|
|
|
inv:set_size("upgrade1", 1)
|
|
|
|
inv:set_size("upgrade2", 1)
|
|
|
|
end,
|
2013-11-27 18:28:56 +01:00
|
|
|
can_dig = technic.machine_can_dig,
|
|
|
|
allow_metadata_inventory_put = technic.machine_inventory_put,
|
|
|
|
allow_metadata_inventory_take = technic.machine_inventory_take,
|
|
|
|
allow_metadata_inventory_move = technic.machine_inventory_move,
|
2013-07-17 21:34:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("technic:"..ltier.."_alloy_furnace_active",{
|
2013-10-30 18:45:32 +01:00
|
|
|
description = S(tier.." Alloy Furnace"),
|
2013-07-17 21:34:35 +02:00
|
|
|
tiles = {"technic_"..ltier.."_alloy_furnace_top.png",
|
|
|
|
"technic_"..ltier.."_alloy_furnace_bottom.png",
|
|
|
|
tube_side_texture,
|
|
|
|
tube_side_texture,
|
|
|
|
"technic_"..ltier.."_alloy_furnace_side.png",
|
|
|
|
"technic_"..ltier.."_alloy_furnace_front_active.png"},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
light_source = 8,
|
|
|
|
drop = "technic:"..ltier.."_alloy_furnace",
|
|
|
|
groups = active_groups,
|
2013-11-26 22:33:27 +01:00
|
|
|
tube = data.tube and tube or nil,
|
2013-07-17 21:34:35 +02:00
|
|
|
legacy_facedir_simple = true,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
2013-11-27 18:28:56 +01:00
|
|
|
can_dig = technic.machine_can_dig,
|
|
|
|
allow_metadata_inventory_put = technic.machine_inventory_put,
|
|
|
|
allow_metadata_inventory_take = technic.machine_inventory_take,
|
|
|
|
allow_metadata_inventory_move = technic.machine_inventory_move,
|
2013-07-17 21:34:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"technic:"..ltier.."_alloy_furnace", "technic:"..ltier.."_alloy_furnace_active"},
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2013-11-26 22:53:52 +01:00
|
|
|
local eu_input = meta:get_int(tier.."_EU_input")
|
2013-07-17 21:34:35 +02:00
|
|
|
|
|
|
|
-- Machine information
|
2013-11-26 22:53:52 +01:00
|
|
|
local machine_name = S("%s Alloy Furnace"):format(tier)
|
|
|
|
local machine_node = "technic:"..ltier.."_alloy_furnace"
|
2013-07-17 21:34:35 +02:00
|
|
|
local machine_demand = data.demand
|
|
|
|
|
|
|
|
-- Setup meta data if it does not exist.
|
|
|
|
if not eu_input then
|
2013-11-26 22:53:52 +01:00
|
|
|
meta:set_int(tier.."_EU_demand", machine_demand[1])
|
|
|
|
meta:set_int(tier.."_EU_input", 0)
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Power off automatically if no longer connected to a switching station
|
2013-11-26 22:53:52 +01:00
|
|
|
technic.switching_station_timeout_count(pos, tier)
|
2013-07-17 21:34:35 +02:00
|
|
|
|
|
|
|
local EU_upgrade, tube_upgrade = 0, 0
|
|
|
|
if data.upgrade then
|
|
|
|
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
|
|
|
|
end
|
|
|
|
if data.tube then
|
|
|
|
technic.handle_machine_pipeworks(pos, tube_upgrade)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Get what to cook if anything
|
|
|
|
local srcstack = inv:get_stack("src", 1)
|
|
|
|
local src2stack = inv:get_stack("src", 2)
|
|
|
|
local recipe = technic.get_alloy_recipe(srcstack, src2stack)
|
|
|
|
local result = recipe and ItemStack(recipe.output) or nil
|
|
|
|
-- Sort the stacks alphabetically
|
|
|
|
if srcstack:get_name() > src2stack:get_name() then
|
|
|
|
local temp = srcstack
|
|
|
|
srcstack = src2stack
|
|
|
|
src2stack = temp
|
|
|
|
end
|
2013-09-24 23:09:20 +02:00
|
|
|
if not result or
|
|
|
|
not inv:room_for_item("dst", result) then
|
2013-12-11 02:14:39 +01:00
|
|
|
technic.swap_node(pos, machine_node)
|
2013-10-30 18:45:32 +01:00
|
|
|
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
2013-11-26 22:53:52 +01:00
|
|
|
meta:set_int(tier.."_EU_demand", 0)
|
2013-07-17 21:34:35 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if eu_input < machine_demand[EU_upgrade+1] then
|
|
|
|
-- Unpowered - go idle
|
2013-12-11 02:14:39 +01:00
|
|
|
technic.swap_node(pos, machine_node)
|
2013-10-30 18:45:32 +01:00
|
|
|
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
2013-07-17 21:34:35 +02:00
|
|
|
elseif eu_input >= machine_demand[EU_upgrade+1] then
|
|
|
|
-- Powered
|
2013-12-11 02:14:39 +01:00
|
|
|
technic.swap_node(pos, machine_node.."_active")
|
2013-10-30 18:45:32 +01:00
|
|
|
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
2013-07-17 21:34:35 +02:00
|
|
|
meta:set_int("src_time", meta:get_int("src_time") + 1)
|
|
|
|
if meta:get_int("src_time") == data.cook_time then
|
|
|
|
meta:set_int("src_time", 0)
|
|
|
|
-- check if there's room for output and that we have the materials
|
|
|
|
if inv:room_for_item("dst", result) then
|
|
|
|
srcstack:take_item(recipe.input[1].count)
|
|
|
|
inv:set_stack("src", 1, srcstack)
|
|
|
|
src2stack:take_item(recipe.input[2].count)
|
|
|
|
inv:set_stack("src", 2, src2stack)
|
|
|
|
-- Put result in "dst" list
|
|
|
|
inv:add_item("dst", result)
|
|
|
|
else
|
|
|
|
next_state = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2013-11-26 22:53:52 +01:00
|
|
|
meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1])
|
2013-07-17 21:34:35 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
technic.register_machine(tier, "technic:"..ltier.."_alloy_furnace", technic.receiver)
|
|
|
|
technic.register_machine(tier, "technic:"..ltier.."_alloy_furnace_active", technic.receiver)
|
|
|
|
|
|
|
|
end -- End registration
|
|
|
|
|