From dd65a68ce9f494717faffc98c45814f9a9d67fa4 Mon Sep 17 00:00:00 2001 From: Zefram Date: Tue, 15 Jul 2014 18:29:36 +0100 Subject: [PATCH] Add centrifuge 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. --- technic/locale/template.txt | 2 ++ technic/machines/MV/centrifuge.lua | 16 +++++++++ technic/machines/MV/init.lua | 1 + technic/machines/register/alloy_recipes.lua | 5 ++- technic/machines/register/centrifuge.lua | 8 +++++ .../machines/register/centrifuge_recipes.lua | 31 ++++++++++++++++++ .../machines/register/compressor_recipes.lua | 2 +- .../machines/register/extractor_recipes.lua | 2 +- technic/machines/register/grinder_recipes.lua | 2 +- technic/machines/register/init.lua | 3 +- technic/machines/register/machine_base.lua | 28 ++++++++++++---- technic/machines/register/recipes.lua | 28 +++++++++++----- .../textures/technic_mv_centrifuge_bottom.png | Bin 0 -> 674 bytes .../textures/technic_mv_centrifuge_front.png | Bin 0 -> 686 bytes .../technic_mv_centrifuge_front_active.png | Bin 0 -> 686 bytes .../textures/technic_mv_centrifuge_side.png | Bin 0 -> 636 bytes .../textures/technic_mv_centrifuge_top.png | Bin 0 -> 814 bytes 17 files changed, 108 insertions(+), 20 deletions(-) create mode 100644 technic/machines/MV/centrifuge.lua create mode 100644 technic/machines/register/centrifuge.lua create mode 100644 technic/machines/register/centrifuge_recipes.lua create mode 100644 technic/textures/technic_mv_centrifuge_bottom.png create mode 100644 technic/textures/technic_mv_centrifuge_front.png create mode 100644 technic/textures/technic_mv_centrifuge_front_active.png create mode 100644 technic/textures/technic_mv_centrifuge_side.png create mode 100644 technic/textures/technic_mv_centrifuge_top.png diff --git a/technic/locale/template.txt b/technic/locale/template.txt index 43090df..3d18f3b 100644 --- a/technic/locale/template.txt +++ b/technic/locale/template.txt @@ -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 index 0000000..5bf24bf --- /dev/null +++ b/technic/machines/MV/centrifuge.lua @@ -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, +}) diff --git a/technic/machines/MV/init.lua b/technic/machines/MV/init.lua index 74eb631..72a98b6 100644 --- a/technic/machines/MV/init.lua +++ b/technic/machines/MV/init.lua @@ -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") diff --git a/technic/machines/register/alloy_recipes.lua b/technic/machines/register/alloy_recipes.lua index 3227739..6f2fc94 100644 --- a/technic/machines/register/alloy_recipes.lua +++ b/technic/machines/register/alloy_recipes.lua @@ -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 index 0000000..dd05977 --- /dev/null +++ b/technic/machines/register/centrifuge.lua @@ -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 index 0000000..0f33c66 --- /dev/null +++ b/technic/machines/register/centrifuge_recipes.lua @@ -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 diff --git a/technic/machines/register/compressor_recipes.lua b/technic/machines/register/compressor_recipes.lua index 73282cf..5c5fe91 100644 --- a/technic/machines/register/compressor_recipes.lua +++ b/technic/machines/register/compressor_recipes.lua @@ -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 diff --git a/technic/machines/register/extractor_recipes.lua b/technic/machines/register/extractor_recipes.lua index d4f8269..41cf56d 100644 --- a/technic/machines/register/extractor_recipes.lua +++ b/technic/machines/register/extractor_recipes.lua @@ -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 diff --git a/technic/machines/register/grinder_recipes.lua b/technic/machines/register/grinder_recipes.lua index 4426f5c..df69665 100644 --- a/technic/machines/register/grinder_recipes.lua +++ b/technic/machines/register/grinder_recipes.lua @@ -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 diff --git a/technic/machines/register/init.lua b/technic/machines/register/init.lua index 55c1f8b..3cf373d 100644 --- a/technic/machines/register/init.lua +++ b/technic/machines/register/init.lua @@ -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") diff --git a/technic/machines/register/machine_base.lua b/technic/machines/register/machine_base.lua index 83c8740..6972b9c 100644 --- a/technic/machines/register/machine_base.lua +++ b/technic/machines/register/machine_base.lua @@ -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) diff --git a/technic/machines/register/recipes.lua b/technic/machines/register/recipes.lua index cff8ca1..1aba96b 100644 --- a/technic/machines/register/recipes.lua +++ b/technic/machines/register/recipes.lua @@ -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 index 0000000000000000000000000000000000000000..6dcd40fd609eb37348c3bc0d5b22577f72e01ac7 GIT binary patch literal 674 zcmV;T0$u%yP)@!p;w^f267wrHdY};(guPAu}}+3LBu{qnviRM+POX z8{&fYii-;rWJ_vEj;9USbIwWL1bV*%6Qnb038YsL$X0kB8}y0-IvMlLH5G;SMu|{s zKoq$IVnVf~S|P3=h017q!In_)_`64-N^OA-igZf*cf~I|swHBIjtUCmhTEkRr-q17 zTaa1&{>yvRU|v>G!xg@qPe>{cA6zk?ZYb}_HSjzK;<~SD%BN4CdG+QuVml!H5lqRm zGrIBe^-G>Se})~LoO3^9t$Xm_kjq1dRipHXJP#{xAHYoko4+7XM$Epi}w zBaR|T%oRF8{`~8YY6)a84m~Y`Z}SY$-jKF29xizD{Mjy96txEa^u>?(y`8DpZdWCU z>2BSYV1iA~$DiMFcViWSSOVz`08DqOT40xs^osi4bY3=u1XJ3V4FpsVj!q6)R2AAQ zsGy^BD_JCk;9|rv5cXfF0`BzGk%-LIdm5EVp(uMvn;K7w!EUjP6A07*qo IM6N<$g89%VeE45bDP46hOx7_4S6Fo+k-*%fF5l(-$> z6XMEkF2Zdo!sjf>Yb&;C+xiU~)@<6mX4RTy{NB>sCc+%r{5)2oypG~r#=<<-qCEEE z+-4%&R-)Xd!mHM;T(@E6!sYW8EnUEEDaxfU$Ym_C8KGT-RR*c(Rn8!wp+f0~4i=R_Zkk>}EI$e{?Sg5y5zpGfUE>o*HSDVjC zf>R$TCB|hW#AP7JV<-Oq|NqE|KOO_U$(ZEr?&9%*>B=i0hqJ&VvKUBvfU(=jY&#(1 zpr?yth{R>vbD7eO4ic>ooxdrjdZ+n(TkFJi^ZJkf|4;OE+wFf}I#1d|Won4kfri}7aLvAp_%+WVY+a`}q+6NQW2c{lRM_m?cxRT@74y_XpT8cJKD+hP=fZ!C^H0h4 zWG9nO2EggLhZ-HJ}CtPgg&ebxsLQ00)2Mx&QzG literal 0 HcmV?d00001 diff --git a/technic/textures/technic_mv_centrifuge_front_active.png b/technic/textures/technic_mv_centrifuge_front_active.png new file mode 100644 index 0000000000000000000000000000000000000000..4cef9123ecb2a436bc1e2afa85f49492f793a458 GIT binary patch literal 686 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJOS+@4BLl<6e(pbstUx|vage(c z!@6@aFM%9|WRD45bDP46hOx7_4S6Fo+k-*%fF5l(-$> z6XMEkF2Zdo!sjf>Yb&;C+xiU~)@<6mX4RTy{NB>sCc+%r{5)2oypG~r#=<<-qCEEE z+-4%&R-)Xd!mHM;T(@E6!sYW8EnUEEDaxfU$Ym}EI$e{?Sg5y5zpGfUE>o*HSDVjC zf>R$TCB|hW#AP7JV<-Oq|NqaM-*N)I$(ZEr?&9%*>B=i0hqJ&VvKUBvfU(=jY&#(1 zpr?yth{R>vbD7eO4ic>ooxdrjdZ+n(TkFJi^ZJkf|4;OE+wFf}I#1d|Won4kfri}7aLvAp_%+WVY+a`}q+6NQW2c{lRM_m?cxRT@74y_XpT8cJKD+hP=fZ!C^H0h4 zWG45bDP46hOx7_4S6Fo+k-*%fF5l-L{K z6XMEkF2Zdo!sjf>Yb&;C+xiU~)@<6mX4RTy{NB>sCc+%r{5)2oypG~r#=<<-qCEEE z+-4%&R-)Xd!mHM;T(@E6!sYW8EnUEEDaxfU$Ym5;z$6kO}+;us=v+4tOYp(XJ4KZaeI{5|rp|ID|)8J?Vw z>X>I!coOJv)e_f;l9a@fRIB8oR3OD*WMF8bYhbQxXc}T@YGrI{Wn`&sU}$Av!1%e_ f3PnS1eoAIqC2kD`>x|og8W=oX{an^LB{Ts5{zlCf literal 0 HcmV?d00001 diff --git a/technic/textures/technic_mv_centrifuge_top.png b/technic/textures/technic_mv_centrifuge_top.png new file mode 100644 index 0000000000000000000000000000000000000000..813bbf8d3c32ece626f84c455fbdcb97048e8a10 GIT binary patch literal 814 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJOS+@4BLl<6e(pbstUx|vage(c z!@6@aFM%9|WRD45bDP46hOx7_4S6Fo+k-*%fF5)TbZd z6XMEkCcRMQ9fr0UVCvK8!>J(VQx#&MN1cO>Iw4Nh;jq97zlEi3Uiwa^H_?^TQZl&N`zA% zC?&>aB*beczI^o}ZYwc9Cy8|%R<2sNa@Cq;n>Mf6uwl)nZRuSV~b?Oh!ynU39_XIoy^ae9n?Gasr|< z!cuZFGOGL%a!OJPB9ihVVp8(r3c}*bqM}lgvT`z<27vL>4nJ@NEQP#yLImw}66gJzX3_BrfZoOAl^#5NUn5SgmDh z>UCcxjY$H$8C)tGkI88t>)ZSN|9|->=YBk_vn)=ZCoUl=d;00trgO)5^SBr-7oJ(9 zv2jzX_2l4f-I@L?_N)@|4gH#(>YtQ$Eyy(Z!!Gfb;;WTyZkw+z>we^SoyUcLixhXa z_i63bf8S*DZn1hTJv;igHFN(|ktMeu|9f}u-@%80hx!&evK^lM;meypk3MPb-FLAh zAh4>s{Qrj^B0-8PG%D*VYpef%SSb)9;{G;lbE3svKbgj^Un&2^m8M5BZ~E$=b~Ui^ z%$k-r`v1=6TxUDKX3CpG{L=r5-tsR_ReJpO_DfK5R4s9hC`m~yNwrEYN(E93Mh1o^ zx(4RDhNdBgrdFoLR;EVU28LD!25)BN+(prlo1c=IR*74~+~Zdgff^V*UHx3vIVCg! E031R7c>n+a literal 0 HcmV?d00001 -- 2.30.2