diff --git a/api.lua b/api.lua index 401d8f7..5e05a8f 100644 --- a/api.lua +++ b/api.lua @@ -20,6 +20,7 @@ industrialtest.api={} industrialtest.api.maceratorRecipes={} industrialtest.api.compressorRecipes={} industrialtest.api.extractorRecipes={} +industrialtest.api.geothermalGeneratorFuels={} industrialtest.api.lvPowerFlow=600 industrialtest.api.mvPowerFlow=2400 @@ -408,3 +409,35 @@ end industrialtest.api.getExtractorRecipeResult=function(recipe) return industrialtest.api.extractorRecipes[recipe] end +-- \brief Registers fuel that can be used in geothermal generator +-- \param fuel Table with following keys: , , +-- which is a table containing items which are tables with following keys: , +-- \returns nil +industrialtest.api.registerGeothermalGeneratorFuel=function(config) + local definition={ + name=config.name or "", + calorificValue=config.calorificValue or 0, + texture=config.texture or "industrialtest_gui_fluid_bg.png", + storageItems=config.storageItems or {} + } + industrialtest.api.geothermalGeneratorFuels[definition.name]=definition +end +-- \brief Returns generator fuel information +-- \param name Name of fuel +-- \returns Table with following keys: name, calorificValue, storageItems +industrialtest.api.getGeothermalGeneratorFuel=function(name) + return industrialtest.api.geothermalGeneratorFuels[name] +end +-- \brief Returns generator fuel information by item name +-- \param name ID of item +-- \returns Table with following keys: name, calorificValue, storageItems or nil in case of failure +industrialtest.api.getGeothermalGeneratorFuelByItem=function(name) + for _,value in pairs(industrialtest.api.geothermalGeneratorFuels) do + for _,item in ipairs(value.storageItems) do + if item.name==name then + return value + end + end + end + return nil +end diff --git a/compatibility.lua b/compatibility.lua index e27bb8a..2a36045 100644 --- a/compatibility.lua +++ b/compatibility.lua @@ -16,8 +16,15 @@ local S=minetest.get_translator("industrialtest") -industrialtest.mtgAvailable=minetest.get_modpath("default") -local requiredMclModules={"mcl_core","mcl_copper","mcl_armor","mcl_deepslate","mcl_nether"} +local requiredMtgModules={"default","bucket"} +industrialtest.mtgAvailable=true +for _,mod in ipairs(requiredMtgModules) do + if not minetest.get_modpath(mod) then + industrialtest.mtgAvailable=false + break + end +end +local requiredMclModules={"mcl_core","mcl_copper","mcl_armor","mcl_deepslate","mcl_nether","mcl_buckets"} industrialtest.mclAvailable=true for _,mod in ipairs(requiredMclModules) do if not minetest.get_modpath(mod) then @@ -493,6 +500,8 @@ if industrialtest.mclAvailable then industrialtest.elementKeys.coal="mcl_core:coal_lump" industrialtest.elementKeys.clay="mcl_core:clay_lump" industrialtest.elementKeys.diamond="mcl_core:diamond" + industrialtest.elementKeys.bucket="mcl_buckets:bucket_empty" + industrialtest.elementKeys.bucketWithLava="mcl_buckets:bucket_lava" industrialtest.elementKeys.glowstone="mcl_nether:glowstone_dust" industrialtest.elementKeys.glass="mcl_core:glass" industrialtest.elementKeys.powerCarrier="mesecons:mesecon" @@ -517,6 +526,7 @@ if industrialtest.mclAvailable then industrialtest.elementKeys.stoneWithGold="mcl_core:stone_with_gold" industrialtest.elementKeys.copperBlock="mcl_copper:block" industrialtest.elementKeys.stoneWithCopper="mcl_copper:stone_with_copper" + industrialtest.elementKeys.lavaSource="mcl_core:lava_source" -- register required minerals that are not available in MCL industrialtest.registerMetal("tin","Tin",3,3) @@ -694,6 +704,8 @@ elseif industrialtest.mtgAvailable then industrialtest.elementKeys.stick="default:stick" industrialtest.elementKeys.flint="default:flint" industrialtest.elementKeys.snowball="default:snow" + industrialtest.elementKeys.bucket="bucket:bucket_empty" + industrialtest.elementKeys.bucketWithLava="bucket:bucket_lava" industrialtest.elementKeys.string="farming:string" industrialtest.elementKeys.junglePlanks="default:junglewood" industrialtest.elementKeys.glowstone="dye:yellow" @@ -723,6 +735,7 @@ elseif industrialtest.mtgAvailable then industrialtest.elementKeys.tinBlock="default:tinblock" industrialtest.elementKeys.stoneWithTin="default:stone_with_tin" industrialtest.elementKeys.bronzeBlock="default:bronzeblock" + industrialtest.elementKeys.lavaSource="default:lava_source" else error("No compatible games found!") end diff --git a/crafts.lua b/crafts.lua index 664694e..4876ac8 100644 --- a/crafts.lua +++ b/crafts.lua @@ -74,3 +74,16 @@ if industrialtest.mclAvailable then count=3 }) end + +-- Geothermal Generator fuels +industrialtest.api.registerGeothermalGeneratorFuel({ + name=industrialtest.elementKeys.lavaSource, + calorificValue=industrialtest.api.lvPowerFlow*2, + texture="industrialtest_gui_lava.png", + storageItems={ + { + name=industrialtest.elementKeys.bucketWithLava, + leftover=industrialtest.elementKeys.bucket + } + } +}) diff --git a/machines.lua b/machines.lua index 42703ad..b15dafe 100644 --- a/machines.lua +++ b/machines.lua @@ -447,6 +447,258 @@ minetest.register_craft({ } }) +local function geothermalGeneratorFormspec(fluidPercent,powerPercent,fluid) + local formspec + local fuel=industrialtest.api.getGeothermalGeneratorFuel(fluid) + local tile=(fuel and fuel.texture or "industrialtest_gui_fluid_bg.png") + if industrialtest.mtgAvailable then + formspec={ + "formspec_version[4]", + "size[10.8,12]", + "label[0.5,0.5;"..S("Geothermal Generator").."]", + "list[context;fluid;2,1.8;1,1]", + "listring[context;fluid]", + (fluidPercent>0 and "image[2,3;1,1;industrialtest_gui_fluid_bg.png^[lowpart:"..fluidPercent..":"..tile.."]" or "image[2,3;1,1;industrialtest_gui_fluid_bg.png]"), + "list[context;leftover;2,4.2;1,1]", + "listring[context;leftover]", + "list[context;charged;6,3;1,1]", + "listring[context;charged]", + "box[9,1;0.3,4.8;#202020]", + (powerPercent>0 and "box[9,"..(1+4.8-(powerPercent*4.8))..";0.3,"..(powerPercent*4.8)..";#FF1010]" or ""), + "list[current_player;main;0.5,6.25;8,1]list[current_player;main;0.5,7.5;8,3;8]" + } + elseif industrialtest.mclAvailable then + formspec={ + "size[10.04,12]", + "label[0.25,0.25;"..S("Geothermal Generator").."]", + "list[context;fluid;2,1.8;1,1]", + mcl_formspec.get_itemslot_bg(2,1.8,1,1), + "listring[context;fluid]", + (fluidPercent>0 and "image[2,3;1,1;industrialtest_gui_fluid_bg.png^[lowpart:"..fluidPercent..":"..tile.."]" or "image[2,3;1,1;industrialtest_gui_fluid_bg.png]"), + "list[context;leftover;2,4.2;1,1]", + mcl_formspec.get_itemslot_bg(2,4.2,1,1), + "listring[context;leftover]", + "list[context;charged;6,3;1,1]", + mcl_formspec.get_itemslot_bg(6,3,1,1), + "listring[context;charged]", + "box[9,1;0.3,4.8;#202020]", + (powerPercent>0 and "box[9,"..(1+4.8-(powerPercent*4.8))..";0.3,"..(powerPercent*4.8)..";#FF1010]" or ""), + "list[current_player;main;0.5,7;9,3;9]", + mcl_formspec.get_itemslot_bg(0.5,7,9,3), + "list[current_player;main;0.5,10.24;9,1]", + mcl_formspec.get_itemslot_bg(0.5,10.24,9,1) + } + end + return table.concat(formspec,"") +end +definition={ + description=S("Geothermal Generator"), + tiles={ + "industrialtest_machine_block.png", + "industrialtest_machine_block.png", + "industrialtest_machine_block.png", + "industrialtest_machine_block.png", + "industrialtest_machine_block.png", + "industrialtest_machine_block.png^industrialtest_geothermal_generator_front.png", + }, + paramtype2="facedir", + legacy_facedir_simple=true, + drop="industrialtest:machine_block", + on_construct=function(pos) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + inv:set_size("charged",1) + inv:set_size("fluid",1) + inv:set_size("leftover",1) + meta:set_float("fluidAmount",0) + meta:set_string("fluid","") + meta:set_string("formspec",geothermalGeneratorFormspec(0,0,"")) + industrialtest.api.addPowerStorage(meta,7000,industrialtest.api.lvPowerFlow,"oooooo") + end, + on_timer=function(pos,elapsed) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local fluidSlot=inv:get_stack("fluid",1) + local chargedSlot=inv:get_stack("charged",1) + local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos) + local shouldUpdateFormspec=false + local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0) + + if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then + local fuel=industrialtest.api.getGeothermalGeneratorFuelByItem(fluidSlot:get_name()) + if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then + local leftover=false + local leftoverAddingSucceeded=false + for _,item in ipairs(fuel.storageItems) do + if item.name==fluidSlot:get_name() and item.leftover then + if inv:room_for_item("leftover",ItemStack(item.leftover)) then + inv:add_item("leftover",ItemStack(item.leftover)) + leftoverAddingSucceeded=true + end + leftover=true + end + end + if not leftover or leftoverAddingSucceeded then + fluidSlot:take_item() + inv:set_stack("fluid",1,fluidSlot) + meta:set_string("fluid",fuel.name) + meta:set_float("fluidAmount",meta:get_float("fluidAmount")+1000) + shouldUpdateFormspec=true + shouldRerunTimer=false + end + end + end + if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then + meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed) + local toAdd=math.ceil(industrialtest.api.getGeothermalGeneratorFuel(meta:get_string("fluid")).calorificValue*elapsed) + industrialtest.api.addPower(meta,toAdd) + shouldUpdateFormspec=true + minetest.swap_node(pos,{ + name="industrialtest:geothermal_generator_active", + param2=minetest.get_node(pos).param2 + }) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + end + if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 then + if industrialtest.api.transferPowerToItem(meta,chargedSlot,industrialtest.api.lvPowerFlow)>0 then + inv:set_stack("charged",1,chargedSlot) + shouldUpdateFormspec=true + shouldRerunTimer=true + end + end + + if shouldUpdateFormspec then + meta:set_string("formspec",geothermalGeneratorFormspec(meta:get_float("fluidAmount")/100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"),meta:get_string("fluid"))) + end + + return shouldRerunTimer + end, + allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local itemstack=inv:get_stack(fromList,fromIndex) + if toList=="charged" and not industrialtest.api.hasPowerStorage(itemstack:get_meta()) then + return 0 + end + return count + end, + allow_metadata_inventory_put=function(pos,listname,index,stack) + if toList=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then + return 0 + end + return stack:get_count() + end, + on_metadata_inventory_move=function(pos) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + end, + on_metadata_inventory_put=function(pos) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + end, + _industrialtest_updateFormspec=function(meta) + meta:set_string("formspec",geothermalGeneratorFormspec(meta:get_float("fluidAmount")/100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"),meta:get_string("fluid"))) + end +} +if industrialtest.mtgAvailable then + definition.groups={ + cracky=1, + level=2 + } + definition.sounds=default.node_sound_metal_defaults() + definition.can_dig=function(pos) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + return not (inv:get_list("charged")[1]:get_count()>0 or inv:get_list("fluid")[1]:get_count()>0) + end +elseif industrialtest.mclAvailable then + definition.after_dig_node=function(pos,oldnode,oldmeta) + mclAfterDigNode(pos,oldmeta,{"charged","fluid"}) + end + definition.groups={pickaxey=1} + definition.sounds=mcl_sounds.node_sound_metal_defaults() + definition._mcl_blast_resistance=3 + definition._mcl_hardness=3.5 +end +definition.groups._industrialtest_hasPowerOutput=1 +definition.groups._industrialtest_wrenchUnmountable=1 +minetest.register_node("industrialtest:geothermal_generator",definition) +definition=table.copy(definition) +definition.description=nil +definition.tiles={ + "industrialtest_machine_block.png", + "industrialtest_machine_block.png", + "industrialtest_machine_block.png", + "industrialtest_machine_block.png", + "industrialtest_machine_block.png", + "industrialtest_machine_block.png^industrialtest_geothermal_generator_front_active.png", +} +definition.on_timer=function(pos,elapsed) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local fluidSlot=inv:get_stack("fluid",1) + local chargedSlot=inv:get_stack("charged",1) + local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos) + local shouldUpdateFormspec=false + local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0) + + if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then + local fuel=industrialtest.api.getGeothermalGeneratorFuelByItem(fluidSlot:get_name()) + if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then + local leftover=false + local leftoverAddingSucceeded=false + for _,item in ipairs(fuel.storageItems) do + if item.name==fluidSlot:get_name() and item.leftover then + if inv:room_for_item("leftover",ItemStack(item.leftover)) then + inv:add_item("leftover",ItemStack(item.leftover)) + leftoverAddingSucceeded=true + end + leftover=true + end + end + if not leftover or leftoverAddingSucceeded then + fluidSlot:take_item() + inv:set_stack("fluid",1,fluidSlot) + meta:set_string("fluid",fuel.name) + meta:set_float("fluidAmount",meta:get_float("fluidAmount")+1000) + minetest.chat_send_all(meta:get_float("fluidAmount")) + shouldUpdateFormspec=true + shouldRerunTimer=false + end + end + end + if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then + meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed) + local toAdd=math.ceil(industrialtest.api.getGeothermalGeneratorFuel(meta:get_string("fluid")).calorificValue*elapsed) + industrialtest.api.addPower(meta,toAdd) + shouldUpdateFormspec=true + shouldRerunTimer=true + else + minetest.swap_node(pos,{ + name="industrialtest:geothermal_generator", + param2=minetest.get_node(pos).param2 + }) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + end + if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 then + if industrialtest.api.transferPowerToItem(meta,chargedSlot,industrialtest.api.lvPowerFlow)>0 then + inv:set_stack("charged",1,chargedSlot) + shouldUpdateFormspec=true + shouldRerunTimer=true + end + end + + if shouldUpdateFormspec then + meta:set_string("formspec",geothermalGeneratorFormspec(meta:get_float("fluidAmount")/100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"),meta:get_string("fluid"))) + end + + return shouldRerunTimer +end +if industrialtest.mclAvailable then + definition.groups.not_in_creative_inventory=1 + definition._doc_items_create_entry=false +end +definition.light_source=8 +minetest.register_node("industrialtest:geothermal_generator_active",definition) + -- Item processing machines local function registerSimpleElectricItemProcessor(config) local function getFormspec(powerPercent,srcPercent) diff --git a/mod.conf b/mod.conf index 1db9c64..52477e1 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name=industrialtest description=Adds various machinery -optional_depends=default,3d_armor,mcl_core,mcl_copper,mcl_armor,mcl_deepslate,mcl_nether +optional_depends=default,bucket,3d_armor,mcl_core,mcl_copper,mcl_armor,mcl_deepslate,mcl_nether,mcl_buckets author=IndustrialTest Team title=IndustrialTest \ No newline at end of file diff --git a/textures/industrialtest_geothermal_generator_front.png b/textures/industrialtest_geothermal_generator_front.png new file mode 100644 index 0000000..bf217de Binary files /dev/null and b/textures/industrialtest_geothermal_generator_front.png differ diff --git a/textures/industrialtest_geothermal_generator_front_active.png b/textures/industrialtest_geothermal_generator_front_active.png new file mode 100644 index 0000000..f3a091b Binary files /dev/null and b/textures/industrialtest_geothermal_generator_front_active.png differ diff --git a/textures/industrialtest_gui_fluid_bg.png b/textures/industrialtest_gui_fluid_bg.png new file mode 100644 index 0000000..124ddfe Binary files /dev/null and b/textures/industrialtest_gui_fluid_bg.png differ diff --git a/textures/industrialtest_gui_lava.png b/textures/industrialtest_gui_lava.png new file mode 100644 index 0000000..1d7039f Binary files /dev/null and b/textures/industrialtest_gui_lava.png differ diff --git a/textures/industrialtest_mcl_refined_iron_ingot.png b/textures/industrialtest_mcl_refined_iron_ingot.png new file mode 100644 index 0000000..122d6c9 Binary files /dev/null and b/textures/industrialtest_mcl_refined_iron_ingot.png differ