From 84014b9d9b1441eb2d31493ece644469121eb7b3 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Wed, 22 Mar 2023 20:57:37 +0100 Subject: [PATCH] Implement Extractor --- api.lua | 12 ++++++++++++ craftitems.lua | 13 ++++++++++++- machines.lua | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/api.lua b/api.lua index 0bb21f1..017b7ea 100644 --- a/api.lua +++ b/api.lua @@ -19,6 +19,7 @@ local S=minetest.get_translator("industrialtest") industrialtest.api={} industrialtest.api.maceratorRecipes={} industrialtest.api.compressorRecipes={} +industrialtest.api.extractorRecipes={} local function clamp(num,min,max) return math.max(math.min(num,max),min) @@ -363,3 +364,14 @@ end industrialtest.api.getCompressorRecipeResult=function(recipe) return industrialtest.api.compressorRecipes[recipe] end +industrialtest.api.registerExtractorRecipe=function(config) + local definition={ + output=config.output or "", + recipe=config.recipe or "", + time=config.time or 2 + } + industrialtest.api.extractorRecipes[definition.recipe]=definition +end +industrialtest.api.getExtractorRecipeResult=function(recipe) + return industrialtest.api.extractorRecipes[recipe] +end diff --git a/craftitems.lua b/craftitems.lua index 0acb912..2949f48 100644 --- a/craftitems.lua +++ b/craftitems.lua @@ -66,7 +66,18 @@ minetest.register_craft({ output="industrialtest:rubber", recipe="industrialtest:sticky_resin" }) --- TODO: add rubber crafts using extractor +industrialtest.api.registerExtractorRecipe({ + output="industrialtest:rubber", + recipe="industrialtest:rubber_wood" +}) +industrialtest.api.registerExtractorRecipe({ + output="industrialtest:rubber", + recipe="industrialtest:rubber_sapling" +}) +industrialtest.api.registerExtractorRecipe({ + output="industrialtest:rubber 3", + recipe="industrialtest:sticky_resin" +}) -- Dust local resources={ diff --git a/machines.lua b/machines.lua index a533452..7e4885a 100644 --- a/machines.lua +++ b/machines.lua @@ -313,6 +313,22 @@ local function registerSimpleElectricItemProcessor(config) time=output.time, src=srcAfter } + elseif method=="industrialtest.extracting" then + local output=industrialtest.api.getExtractorRecipeResult(item:get_name()) + if not output then + return { + item=ItemStack(), + time=0, + src=item + } + end + local srcAfter=ItemStack(item:get_name()) + srcAfter:set_count(item:get_count()-1) + return { + item=ItemStack(output.output), + time=output.time, + src=srcAfter + } end error("Unknown craft method passed to craftResultProxy") end @@ -779,3 +795,21 @@ minetest.register_craft({ {industrialtest.elementKeys.stone,"industrialtest:electronic_circuit",industrialtest.elementKeys.stone} } }) + +registerSimpleElectricItemProcessor({ + name="extractor", + displayName="Extractor", + capacity=900, + flow=600, + opPower=100, + method="industrialtest.extracting", + efficiency=1 +}) +minetest.register_craft({ + type="shaped", + output="industrialtest:extractor", + recipe={ + {"industrialtest:treetap","industrialtest:machine_block","industrialtest:treetap"}, + {"industrialtest:treetap","industrialtest:electronic_circuit","industrialtest:treetap"} + } +})