Add centrifuge
authorZefram <zefram@fysh.org>
Tue, 15 Jul 2014 17:29:36 +0000 (18:29 +0100)
committerZefram <zefram@fysh.org>
Sat, 26 Jul 2014 17:01:05 +0000 (18:01 +0100)
The centrifuge, currently only existing in an MV variety, is a machine
that separates a mixed substance into its constituents.  Currently the
main use is to reverse alloying of metals.  The alloy separation recipes
intentionally only operate on the dust form of metals, making this less
convenient than the original alloying.  It also only recovers metal
constituents, not the carbon that went into cast iron or carbon steel.

This change incidentally generalises the technic recipe and
machine infrastructure to handle recipes with multiple outputs.
As unified_inventory's craft guide can't yet handle that, these recipes
are not registered there.

17 files changed:
technic/locale/template.txt
technic/machines/MV/centrifuge.lua [new file with mode: 0644]
technic/machines/MV/init.lua
technic/machines/register/alloy_recipes.lua
technic/machines/register/centrifuge.lua [new file with mode: 0644]
technic/machines/register/centrifuge_recipes.lua [new file with mode: 0644]
technic/machines/register/compressor_recipes.lua
technic/machines/register/extractor_recipes.lua
technic/machines/register/grinder_recipes.lua
technic/machines/register/init.lua
technic/machines/register/machine_base.lua
technic/machines/register/recipes.lua
technic/textures/technic_mv_centrifuge_bottom.png [new file with mode: 0644]
technic/textures/technic_mv_centrifuge_front.png [new file with mode: 0644]
technic/textures/technic_mv_centrifuge_front_active.png [new file with mode: 0644]
technic/textures/technic_mv_centrifuge_side.png [new file with mode: 0644]
technic/textures/technic_mv_centrifuge_top.png [new file with mode: 0644]

index 43090dff4a1b009f46611d80565a9d6bd0183fcd..3d18f3b567e8b29abd040f09a2b23a3d2d7828b3 100644 (file)
@@ -64,6 +64,7 @@ Controlled by Mesecon Signal =
 %s Battery Box = 
 %s Cable =
 %s CNC Machine =
+%s Centrifuge =
 %s Compressor =
 %s Extractor =
 %s Forcefield Emitter =
@@ -190,3 +191,4 @@ Alloy cooking =
 Grinding =
 Compressing =
 Extracting =
+Separating =
diff --git a/technic/machines/MV/centrifuge.lua b/technic/machines/MV/centrifuge.lua
new file mode 100644 (file)
index 0000000..5bf24bf
--- /dev/null
@@ -0,0 +1,16 @@
+minetest.register_craft({
+       output = "technic:mv_centrifuge",
+       recipe = {
+               { "technic:motor",          "technic:copper_plate",   "technic:diamond_drill_head" },
+               { "technic:copper_plate",   "technic:machine_casing", "technic:copper_plate"       },
+               { "pipeworks:one_way_tube", "technic:mv_cable0",      "pipeworks:mese_filter"      },
+       }
+})
+
+technic.register_centrifuge({
+       tier = "MV",
+       demand = { 8000, 7000, 6000 },
+       speed = 2,
+       upgrade = 1,
+       tube = 1,
+})
index 74eb631642deb4e31789fbda9ce57b32488add83..72a98b6f8670bcdeef1222f49cc8cd6c9ee2987f 100644 (file)
@@ -20,6 +20,7 @@ dofile(path.."/electric_furnace.lua")
 dofile(path.."/grinder.lua")
 dofile(path.."/extractor.lua")
 dofile(path.."/compressor.lua")
+dofile(path.."/centrifuge.lua")
 
 dofile(path.."/tool_workshop.lua")
 
index 3227739e2bcc5bcc399ce3bd970705281cf6541e..6f2fc948087dca5f43a0981a1f8d3167748cc179 100644 (file)
@@ -1,7 +1,10 @@
 
 local S = technic.getter
 
-technic.register_recipe_type("alloy", S("Alloy cooking"), 2)
+technic.register_recipe_type("alloy", {
+       description = S("Alloy cooking"),
+       input_size = 2,
+})
 
 function technic.register_alloy_recipe(data)
        data.time = data.time or 6
diff --git a/technic/machines/register/centrifuge.lua b/technic/machines/register/centrifuge.lua
new file mode 100644 (file)
index 0000000..dd05977
--- /dev/null
@@ -0,0 +1,8 @@
+local S = technic.getter
+
+function technic.register_centrifuge(data)
+       data.typename = "separating"
+       data.machine_name = "centrifuge"
+       data.machine_desc = S("%s Centrifuge")
+       technic.register_base_machine(data)
+end
diff --git a/technic/machines/register/centrifuge_recipes.lua b/technic/machines/register/centrifuge_recipes.lua
new file mode 100644 (file)
index 0000000..0f33c66
--- /dev/null
@@ -0,0 +1,31 @@
+local S = technic.getter
+
+technic.register_recipe_type("separating", {
+       description = S("Separating"),
+       output_size = 2,
+})
+
+function technic.register_separating_recipe(data)
+       data.time = data.time or 10
+       technic.register_recipe("separating", data)
+end
+
+local rubber_tree_planks = minetest.get_modpath("moretrees") and "moretrees:rubber_tree_planks" or "default:wood"
+
+local recipes = {
+       { "technic:bronze_dust 4",             "technic:copper_dust 3",       "technic:tin_dust"      },
+       { "technic:stainless_steel_dust 4",    "technic:wrought_iron_dust 3", "technic:chromium_dust" },
+       { "technic:brass_dust 3",              "technic:copper_dust 2",       "technic:zinc_dust"     },
+       { "moretrees:rubber_tree_trunk_empty", rubber_tree_planks.." 4",      "technic:raw_latex"     },
+       { "moretrees:rubber_tree_trunk",       rubber_tree_planks.." 4",      "technic:raw_latex"     },
+}
+
+if minetest.get_modpath("bushes_classic") then
+       for _, berry in ipairs({ "blackberry", "blueberry", "gooseberry", "raspberry", "strawberry" }) do
+               table.insert(recipes, { "bushes:"..berry.."_bush", "default:stick 20", "bushes:"..berry.." 4" })
+       end
+end
+
+for _, data in pairs(recipes) do
+       technic.register_separating_recipe({ input = { data[1] }, output = { data[2], data[3] } })
+end
index 73282cfb9dcf5d18f5ce044d288aefdd89ed2a94..5c5fe9190ac4c8cceb7c9ec9e762c4e3c3f47ceb 100644 (file)
@@ -1,7 +1,7 @@
 
 local S = technic.getter
 
-technic.register_recipe_type("compressing", S("Compressing"))
+technic.register_recipe_type("compressing", { description = S("Compressing") })
 
 function technic.register_compressor_recipe(data)
        data.time = data.time or 4
index d4f8269eb353ea3d28cdcbb00114b94cb3bce8c4..41cf56d53a1a06efa1e4590c973302c11d6fb517 100644 (file)
@@ -1,7 +1,7 @@
 
 local S = technic.getter
 
-technic.register_recipe_type("extracting", S("Extracting"))
+technic.register_recipe_type("extracting", { description = S("Extracting") })
 
 function technic.register_extractor_recipe(data)
        data.time = data.time or 4
index 4426f5c692b2377d4b077e42d4207782a3dfd8a6..df696656b1a253b26b6e16dd99f6c42400768d52 100644 (file)
@@ -1,7 +1,7 @@
 
 local S = technic.getter
 
-technic.register_recipe_type("grinding", S("Grinding"))
+technic.register_recipe_type("grinding", { description = S("Grinding") })
 
 function technic.register_grinder_recipe(data)
        data.time = data.time or 3
index 55c1f8b24712a5c7a332c2180f0d2594d802bc5a..3cf373d28defc41d52f2c484fe3359f4019bdfa3 100644 (file)
@@ -19,6 +19,7 @@ dofile(path.."/alloy_recipes.lua")
 dofile(path.."/grinder_recipes.lua")
 dofile(path.."/extractor_recipes.lua")
 dofile(path.."/compressor_recipes.lua")
+dofile(path.."/centrifuge_recipes.lua")
 
 -- Machines
 dofile(path.."/alloy_furnace.lua")
@@ -26,4 +27,4 @@ dofile(path.."/electric_furnace.lua")
 dofile(path.."/grinder.lua")
 dofile(path.."/extractor.lua")
 dofile(path.."/compressor.lua")
-
+dofile(path.."/centrifuge.lua")
index 83c8740dd7303259712c65342899fe2b4eff133f..6972b9c05c8e20aeb13f04cd0c285e6f7c41e66a 100644 (file)
@@ -17,7 +17,7 @@ local tube = {
 
 function technic.register_base_machine(data)
        local typename = data.typename
-       local numitems = technic.recipes[typename].numitems
+       local input_size = technic.recipes[typename].input_size
        local machine_name = data.machine_name
        local machine_desc = data.machine_desc
        local tier = data.tier
@@ -35,7 +35,7 @@ function technic.register_base_machine(data)
 
        local formspec =
                "invsize[8,9;]"..
-               "list[current_name;src;"..(4-numitems)..",1;"..numitems..",1;]"..
+               "list[current_name;src;"..(4-input_size)..",1;"..input_size..",1;]"..
                "list[current_name;dst;5,1;2,2;]"..
                "list[current_player;main;0,5;8,4;]"..
                "label[0,0;"..machine_desc:format(tier).."]"
@@ -91,10 +91,26 @@ function technic.register_base_machine(data)
                        meta:set_int("src_time", meta:get_int("src_time") + 1)
                        if meta:get_int("src_time") >= result.time / data.speed then
                                meta:set_int("src_time", 0)
-                               local result_stack = ItemStack(result.output)
-                               if inv:room_for_item("dst", result_stack) then
+                               local output = result.output
+                               if type(output) ~= "table" then output = { output } end
+                               local output_stacks = {}
+                               for _, o in ipairs(output) do
+                                       table.insert(output_stacks, ItemStack(o))
+                               end
+                               local room_for_output = true
+                               inv:set_size("dst_tmp", inv:get_size("dst"))
+                               inv:set_list("dst_tmp", inv:get_list("dst"))
+                               for _, o in ipairs(output_stacks) do
+                                       if not inv:room_for_item("dst_tmp", o) then
+                                               room_for_output = false
+                                               break
+                                       end
+                                       inv:add_item("dst_tmp", o)
+                               end
+                               if room_for_output then
                                        inv:set_list("src", result.new_input)
-                                       inv:add_item("dst", result_stack)
+                                       inv:set_list("dst", inv:get_list("dst_tmp"))
+                               else
                                end
                        end
                end
@@ -121,7 +137,7 @@ function technic.register_base_machine(data)
                        meta:set_int("tube_time",  0)
                        meta:set_string("formspec", formspec)
                        local inv = meta:get_inventory()
-                       inv:set_size("src", numitems)
+                       inv:set_size("src", input_size)
                        inv:set_size("dst", 4)
                        inv:set_size("upgrade1", 1)
                        inv:set_size("upgrade2", 1)
index cff8ca1f8b52c33c00c9c3aab43648dccfe47e46..1aba96b0ce1fbc9473b46809a8f9eda903267fee 100644 (file)
@@ -1,15 +1,19 @@
 
-technic.recipes = {cooking = {numitems = 1}}
-function technic.register_recipe_type(typename, desc, numitems)
-       numitems = numitems or 1
-       if unified_inventory and unified_inventory.register_craft_type then
+technic.recipes = { cooking = { input_size = 1, output_size = 1 } }
+function technic.register_recipe_type(typename, origdata)
+       local data = {}
+       for k, v in pairs(origdata) do data[k] = v end
+       data.input_size = data.input_size or 1
+       data.output_size = data.output_size or 1
+       if unified_inventory and unified_inventory.register_craft_type and data.output_size == 1 then
                unified_inventory.register_craft_type(typename, {
-                       description = desc,
-                       height = numitems,
+                       description = data.description,
+                       height = data.input_size,
                        width = 1,
                })
        end
-       technic.recipes[typename] = {numitems = numitems, recipes = {}}
+       data.recipes = {}
+       technic.recipes[typename] = data
 end
 
 local function get_recipe_index(items)
@@ -26,7 +30,13 @@ local function register_recipe(typename, data)
        for i, stack in ipairs(data.input) do
                data.input[i] = ItemStack(stack):to_string()
        end
-       data.output = ItemStack(data.output):to_string()
+       if type(data.output) == "table" then
+               for i, v in ipairs(data.output) do
+                       data.output[i] = ItemStack(data.output[i]):to_string()
+               end
+       else
+               data.output = ItemStack(data.output):to_string()
+       end
        
        local recipe = {time = data.time, input = {}, output = data.output}
        local index = get_recipe_index(data.input)
@@ -35,7 +45,7 @@ local function register_recipe(typename, data)
        end
        
        technic.recipes[typename].recipes[index] = recipe
-       if unified_inventory then
+       if unified_inventory and technic.recipes[typename].output_size == 1 then
                unified_inventory.register_craft({
                        type = typename,
                        output = data.output,
diff --git a/technic/textures/technic_mv_centrifuge_bottom.png b/technic/textures/technic_mv_centrifuge_bottom.png
new file mode 100644 (file)
index 0000000..6dcd40f
Binary files /dev/null and b/technic/textures/technic_mv_centrifuge_bottom.png differ
diff --git a/technic/textures/technic_mv_centrifuge_front.png b/technic/textures/technic_mv_centrifuge_front.png
new file mode 100644 (file)
index 0000000..e278a33
Binary files /dev/null and b/technic/textures/technic_mv_centrifuge_front.png differ
diff --git a/technic/textures/technic_mv_centrifuge_front_active.png b/technic/textures/technic_mv_centrifuge_front_active.png
new file mode 100644 (file)
index 0000000..4cef912
Binary files /dev/null and b/technic/textures/technic_mv_centrifuge_front_active.png differ
diff --git a/technic/textures/technic_mv_centrifuge_side.png b/technic/textures/technic_mv_centrifuge_side.png
new file mode 100644 (file)
index 0000000..eeef44a
Binary files /dev/null and b/technic/textures/technic_mv_centrifuge_side.png differ
diff --git a/technic/textures/technic_mv_centrifuge_top.png b/technic/textures/technic_mv_centrifuge_top.png
new file mode 100644 (file)
index 0000000..813bbf8
Binary files /dev/null and b/technic/textures/technic_mv_centrifuge_top.png differ