-- IndustrialTest -- Copyright (C) 2023 mrkubax10 -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . local S=minetest.get_translator("industrialtest") -- Generators local function generatorFormspec(fuelPercent,charged) local formspec if industrialtest.mtgAvailable then formspec={ "formspec_version[4]", "size[10.8,12]", "label[0.5,0.5;"..S("Generator").."]", "list[context;charged;4.9,1.8;1,1]", "listring[context;charged]", (fuelPercent>0 and "image[4.9,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]" or "image[4.9,2.8;1,1;default_furnace_fire_bg.png]"), "list[context;fuel;4.9,3.9;1,1]", "listring[context;fuel]", "box[9,1;0.3,4.8;#202020]", (charged>0 and "box[9,"..(1+4.8-(charged*4.8))..";0.3,"..(charged*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("Generator").."]", "list[context;charged;4.7,1.8;1,1]", mcl_formspec.get_itemslot_bg(4.7,1.8,1,1), "listring[context;charged]", (fuelPercent>0 and "image[4.7,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]" or "image[4.7,2.8;1,1;default_furnace_fire_bg.png]"), "list[context;fuel;4.7,3.9;1,1]", mcl_formspec.get_itemslot_bg(4.7,3.9,1,1), "listring[context;fuel]", "box[9,1;0.3,4.8;#202020]", (charged>0 and "box[9,"..(1+4.8-(charged*4.8))..";0.3,"..(charged*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 local function mclAfterDigNode(pos,oldmeta,lists) -- Taken from https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/ITEMS/mcl_furnaces/init.lua#L538 local meta=minetest.get_meta(pos) local meta2=meta meta:from_table(oldmeta) local inv=meta:get_inventory() for _,listname in ipairs(lists) do local stack=inv:get_stack(listname,1) if not stack:is_empty() then local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} minetest.add_item(p, stack) end end meta:from_table(meta2:to_table()) end local definition={ description=S("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_iron_furnace_front.png", "industrialtest_machine_block.png" }, paramtype2="facedir", legacy_facedir_simple=true, on_construct=function(pos,placer) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() inv:set_size("charged",1) inv:set_size("fuel",1) meta:set_string("formspec",generatorFormspec(0,0)) meta:set_int("fuelTime",0) meta:set_int("maxFuelTime",1) industrialtest.api.addPowerStorage(meta,7000,industrialtest.api.lvPowerFlow,"oooooo") minetest.get_node_timer(pos):start(industrialtest.updateDelay) end, on_timer=function(pos,elapsed) local meta=minetest.get_meta(pos) local powerFlow=meta:get_int("industrialtest.powerFlow") local inv=meta:get_inventory() local chargedSlot=inv:get_stack("charged",1) local fuelSlot=inv:get_stack("fuel",1) local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos) local shouldUpdateFormspec=flowTransferred local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0) if chargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(chargedSlot:get_meta()) and meta:get_int("industrialtest.powerAmount")>0 then industrialtest.api.transferPowerToItem(meta,chargedSlot,powerFlow) inv:set_stack("charged",1,chargedSlot) shouldUpdateFormspec=true shouldRerunTimer=true end if fuelSlot:get_count()>0 and meta:get_int("fuelTime")<=0 and not industrialtest.api.isFullyCharged(meta) then local output,after=minetest.get_craft_result({ method="fuel", width=1, items={fuelSlot} }) if output.time>0 then meta:set_int("fuelTime",output.time) meta:set_int("maxFuelTime",output.time) inv:set_stack("fuel",1,after.items[1]) minetest.swap_node(pos,{ name="industrialtest:generator_active", param2=minetest.get_node(pos).param2 }) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end end if shouldUpdateFormspec then meta:set_string("formspec",generatorFormspec(meta:get_int("fuelTime")/meta:get_int("maxFuelTime")*100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"))) end return shouldRerunTimer end, allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count,player) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local movedItemStack=inv:get_list(fromList)[1] if toList=="charged" and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) then return 0 end return count end, allow_metadata_inventory_put=function(pos,listname,index,stack,player) if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then return 0 end return stack:get_count() end, on_metadata_inventory_put=function(pos,listname,index,stack,player) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end, on_metadata_inventory_take=function(pos,listname,index,stack,player) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end, _industrialtest_updateFormspec=function(meta) meta:set_string("formspec",generatorFormspec(meta:get_int("fuelTime")/meta:get_int("maxFuelTime")*100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"))) end } if industrialtest.mtgAvailable then definition.groups={cracky=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("fuel")[1]:get_count()>0) end elseif industrialtest.mclAvailable then definition.after_dig_node=function(pos,oldnode,oldmeta) mclAfterDigNode(pos,oldmeta,{"charged","fuel"}) end definition.groups={pickaxey=1} definition.sounds=mcl_sounds.node_sound_metal_defaults() definition._mcl_blast_resistance=3.5 definition._mcl_hardness=3.9 end definition.groups._industrialtest_hasPowerOutput=1 definition.groups._industrialtest_wrenchUnmountable=1 minetest.register_node("industrialtest: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_iron_furnace_front_active.png", "industrialtest_machine_block.png" } definition.drop="industrialtest:generator" definition.light_source=8 definition.on_timer=function(pos,elapsed) local meta=minetest.get_meta(pos) local powerFlow=meta:get_int("industrialtest.powerFlow") local inv=meta:get_inventory() local chargedSlot=inv:get_stack("charged",1) local fuelSlot=inv:get_stack("fuel",1) local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos) local shouldUpdateFormspec=flowTransferred local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0) if chargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(chargedSlot:get_meta()) and meta:get_int("industrialtest.powerAmount")>0 then industrialtest.api.transferPowerToItem(meta,chargedSlot,powerFlow) inv:set_stack("charged",1,chargedSlot) shouldUpdateFormspec=true shouldRerunTimer=true end if fuelSlot:get_count()>0 and meta:get_int("fuelTime")<=0 and not industrialtest.api.isFullyCharged(meta) then local output,after=minetest.get_craft_result({ method="fuel", width=1, items={fuelSlot} }) if output.time>0 then meta:set_int("fuelTime",output.time) meta:set_int("maxFuelTime",output.time) inv:set_stack("fuel",1,after.items[1]) end end if meta:get_int("fuelTime")>0 then meta:set_int("fuelTime",meta:get_int("fuelTime")-elapsed) industrialtest.api.addPower(meta,200) shouldUpdateFormspec=true shouldRerunTimer=true else minetest.swap_node(pos,{ name="industrialtest:generator", param2=minetest.get_node(pos).param2 }) end if shouldUpdateFormspec then meta:set_string("formspec",generatorFormspec(meta:get_int("fuelTime")/meta:get_int("maxFuelTime")*100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"))) end return shouldRerunTimer end if industrialtest.mclAvailable then definition.groups.not_in_creative_inventory=1 definition._doc_items_create_entry=false end minetest.register_node("industrialtest:generator_active",definition) minetest.register_craft({ type="shaped", output="industrialtest:generator", recipe={ {"industrialtest:re_battery"}, {"industrialtest:machine_block"}, {industrialtest.elementKeys.furnace} } }) minetest.register_craft({ type="shaped", output="industrialtest:generator", recipe={ {"","industrialtest:re_battery",""}, {"industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot"}, {"","industrialtest:iron_furnace",""} } }) local function registerSolarPanelGenerator(config) local function getFormspec(charging) local formspec if industrialtest.mtgAvailable then formspec={ "formspec_version[4]", "size[10.8,12]", "label[0.5,0.5;"..S(config.displayName).."]", "list[context;charged;4.9,1.8;1,1]", "listring[context;charged]", (charging and "image[4.9,2.8;1,1;industrialtest_gui_sun_fg.png]" or "image[4.9,2.8;1,1;industrialtest_gui_sun_bg.png]"), "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(config.displayName).."]", "list[context;charged;4.7,1.8;1,1]", mcl_formspec.get_itemslot_bg(4.7,1.8,1,1), "listring[context;charged]", (charging and "image[4.7,2.8;1,1;industrialtest_gui_sun_fg.png]" or "image[4.7,2.8;1,1;industrialtest_gui_sun_bg.png]"), "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(config.displayName), tiles={ "industrialtest_machine_block.png^industrialtest_"..config.name.."_top.png", "industrialtest_machine_block.png" }, drop="industrialtest:machine_block", on_construct=function(pos) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() inv:set_size("charged",1) meta:set_string("formspec",getFormspec(false)) meta:set_float("prevAmount",0) industrialtest.api.addPowerStorage(meta,config.capacity,config.flow,"oooooo") minetest.get_node_timer(pos):start(industrialtest.updateDelay) end, on_timer=function(pos,elapsed) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local chargedSlot=inv:get_stack("charged",1) local shouldUpdateFormspec=false local amount=minetest.get_natural_light(vector.offset(pos,0,1,0))/15.0 local charging=amount>0.5 if charging then industrialtest.api.addPower(meta,math.ceil(amount*config.flow*elapsed)) end if meta:get_int("industrialtest.powerAmount")>0 then if chargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(chargedSlot:get_meta()) then industrialtest.api.transferPowerToItem(meta,chargedSlot,math.ceil(config.flow*elapsed)) inv:set_stack("charged",1,chargedSlot) end industrialtest.api.powerFlow(pos) end if amount~=meta:get_float("prevAmount") then shouldUpdateFormspec=true meta:set_float("prevAmount",amount) end if shouldUpdateFormspec then meta:set_string("formspec",getFormspec(charging)) end return true end, allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local movedItemStack=inv:get_list(fromList)[1] if toList=="charged" and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) then return 0 end return count end, allow_metadata_inventory_put=function(pos,listname,index,stack) if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then return 0 end return stack:get_count() end, on_metadata_inventory_put=function(pos) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end, on_metadata_inventory_take=function(pos) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end } if industrialtest.mtgAvailable then definition.groups={cracky=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 inv:get_list("charged")[1]:get_count()==0 end elseif industrialtest.mclAvailable then definition.groups={pickaxey=1} definition.sounds=mcl_sounds.node_sound_metal_defaults() definition._mcl_blast_resistance=1 definition._mcl_hardness=3.9 definition.after_dig_node=function(pos,oldnode,oldmeta) mclAfterDigNode(pos,oldmeta,{"charged"}) end end definition.groups._industrialtest_hasPowerOutput=1 definition.groups._industrialtest_wrenchUnmountable=1 minetest.register_node("industrialtest:"..config.name,definition) end registerSolarPanelGenerator({ name="solar_panel", displayName="Solar Panel", capacity=industrialtest.api.lvPowerFlow*2, flow=industrialtest.api.lvPowerFlow }) minetest.register_craft({ type="shaped", output="industrialtest:solar_panel", recipe={ {"industrialtest:coal_dust",industrialtest.elementKeys.glass,"industrialtest:coal_dust"}, {industrialtest.elementKeys.glass,"industrialtest:coal_dust",industrialtest.elementKeys.glass}, {"industrialtest:insulated_copper_cable","industrialtest:generator","industrialtest:insulated_copper_cable"} } }) registerSolarPanelGenerator({ name="lv_solar_array", displayName="LV Solar Array", capacity=industrialtest.api.lvPowerFlow*4, flow=industrialtest.api.lvPowerFlow*2 }) minetest.register_craft({ type="shaped", output="industrialtest:lv_solar_array", recipe={ {"industrialtest:solar_panel","industrialtest:solar_panel","industrialtest:solar_panel"}, {"industrialtest:solar_panel","industrialtest:lv_transformer","industrialtest:solar_panel"}, {"industrialtest:solar_panel","industrialtest:solar_panel","industrialtest:solar_panel"} } }) registerSolarPanelGenerator({ name="mv_solar_array", displayName="MV Solar Array", capacity=industrialtest.api.mvPowerFlow*2, flow=industrialtest.api.mvPowerFlow }) minetest.register_craft({ type="shaped", output="industrialtest:mv_solar_array", recipe={ {"industrialtest:lv_solar_array","industrialtest:lv_solar_array","industrialtest:lv_solar_array"}, {"industrialtest:lv_solar_array","industrialtest:mv_transformer","industrialtest:lv_solar_array"}, {"industrialtest:lv_solar_array","industrialtest:lv_solar_array","industrialtest:lv_solar_array"} } }) registerSolarPanelGenerator({ name="hv_solar_array", displayName="HV Solar Array", capacity=industrialtest.api.hvPowerFlow*2, flow=industrialtest.api.hvPowerFlow }) minetest.register_craft({ type="shaped", output="industrialtest:hv_solar_array", recipe={ {"industrialtest:mv_solar_array","industrialtest:mv_solar_array","industrialtest:mv_solar_array"}, {"industrialtest:mv_solar_array","industrialtest:hv_transformer","industrialtest:mv_solar_array"}, {"industrialtest:mv_solar_array","industrialtest:mv_solar_array","industrialtest:mv_solar_array"} } }) 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) local formspec if industrialtest.mtgAvailable then formspec={ "formspec_version[4]", "size[10.8,12]", "label[0.5,0.5;"..S(config.displayName).."]", "list[context;src;3.4,1.8;1,1]", "listring[context;src]", (powerPercent>0 and "image[3.4,2.8;1,1;industrialtest_gui_electricity_bg.png^[lowpart:"..powerPercent..":industrialtest_gui_electricity_fg.png]" or "image[3.4,2.8;1,1;industrialtest_gui_electricity_bg.png]"), "list[context;powerStorage;3.4,3.9;1,1]", "listring[context;powerStorage]", (srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]" or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"), "list[context;dst;6.4,2.8;1,1]", "listring[context;dst]", "list[context;upgrades;9,0.9;1,4]", "listring[context;upgrades]", "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(config.displayName).."]", "list[context;src;3.4,1.8;1,1]", mcl_formspec.get_itemslot_bg(3.4,1.8,1,1), "listring[context;src]", (powerPercent>0 and "image[3.4,2.8;1,1;industrialtest_gui_electricity_bg.png^[lowpart:"..powerPercent..":industrialtest_gui_electricity_fg.png]" or "image[3.4,2.8;1,1;industrialtest_gui_electricity_bg.png]"), "list[context;powerStorage;3.4,3.9;1,1]", mcl_formspec.get_itemslot_bg(3.4,3.9,1,1), "listring[context;powerStorage]", (srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]" or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"), "list[context;dst;6.4,2.8;1,1]", mcl_formspec.get_itemslot_bg(6.4,2.8,1,1), "listring[context;dst]", "list[context;upgrades;9,0.9;1,4]", mcl_formspec.get_itemslot_bg(9,0.9,1,4), "listring[context;upgrades]", "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 local function craftResultProxy(method,item) if method=="cooking" then local output,after=minetest.get_craft_result({ method=method, width=1, items={item} }) return { item=output.item, time=output.time, src=after.items[1] } elseif method=="industrialtest.macerating" then local output=industrialtest.api.getMaceratorRecipeResult(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 } elseif method=="industrialtest.compressing" then local output=industrialtest.api.getCompressorRecipeResult(item:get_name()) if not output or item:get_count()0 then local stackMeta=powerStorageSlot:get_meta() if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then shouldUpdateFormspec=true shouldRerunTimer=true industrialtest.api.updateItemPowerText(powerStorageSlot) inv:set_stack("powerStorage",1,powerStorageSlot) end end if srcSlot:get_count()>0 and meta:get_float("maxSrcTime")<=0 and meta:get_int("industrialtest.powerAmount")>=requiredPower then local output=craftResultProxy(config.method,srcSlot) if output.time>0 and inv:room_for_item("dst",output.item) then meta:set_float("srcTime",0) meta:set_float("maxSrcTime",output.time*config.efficiency) minetest.swap_node(pos,{ name="industrialtest:"..config.name.."_active", param2=minetest.get_node(pos).param2 }) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end end if not industrialtest.api.isFullyCharged(meta) then industrialtest.api.triggerNeighbours(pos) end if shouldUpdateFormspec then meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) end return shouldRerunTimer end, allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,count) if toList=="dst" then return 0 elseif toList=="powerStorage" then local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local stack=inv:get_stack(fromList,fromIndex) return (industrialtest.api.hasPowerStorage(stack:get_meta()) and count or 0) elseif toList=="upgrades" then -- TODO: Add support for upgrades when they will be added return 0 end return count end, allow_metadata_inventory_put=function(pos,listname,index,stack) if listname=="dst" then return 0 elseif listname=="src" then local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) if srcSlot:get_name()~=stack:get_name() then meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) end elseif listname=="powerStorage" then return (industrialtest.api.hasPowerStorage(stack:get_meta()) and stack:get_count() or 0) elseif listname=="upgrades" then --TODO: See allow_metadata_inventory_move return 0 end return stack:get_count() end, on_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) local dstSlot=inv:get_stack("dst",1) if fromList=="src" and count==srcSlot:get_count() then meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) if meta:get_int("industrialtest.powerAmount")>0 then meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) end elseif fromList=="dst" and dstSlot:get_free_space()==0 then minetest.get_node_timer(pos):start(industrialtest.updateDelay) end end, on_metadata_inventory_put=function(pos,listname) if listname=="src" or listname=="powerStorage" then minetest.get_node_timer(pos):start(industrialtest.updateDelay) end end, on_metadata_inventory_take=function(pos,listname,index,stack) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) local dstSlot=inv:get_stack("dst",1) if listname=="src" and stack:get_count()==srcSlot:get_count() then meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) if meta:get_int("industrialtest.powerAmount")>0 then meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) end elseif listname=="dst" and dstSlot:get_free_space()==0 then minetest.get_node_timer(pos):start(industrialtest.updateDelay) end end, _industrialtest_updateFormspec=function(meta) meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) end, _industrialtest_onPowerFlow=function(pos) -- FIXME: this probably will require refactor so node timer won't be started -- just to test if machine can process item minetest.get_node_timer(pos):start(industrialtest.updateDelay) 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("src")[1]:get_count()>0 or inv:get_list("powerStorage")[1]:get_count()>0 or inv:get_list("dst")[1]:get_count()>0) end elseif industrialtest.mclAvailable then definition.after_dig_node=function(pos,oldnode,oldmeta) mclAfterDigNode(pos,oldmeta,{"src","powerStorage","dst","upgrades"}) 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_hasPowerInput=1 definition.groups._industrialtest_wrenchUnmountable=1 minetest.register_node("industrialtest:"..config.name,definition) definition=table.copy(definition) definition.description=nil definition.tiles={ "industrialtest_machine_block.png"..(config.customTopTexture and "^industrialtest_"..config.name.."_top_active.png" or ""), "industrialtest_machine_block.png"..(config.customBottomTexture and "^industrialtest_"..config.name.."_bottom_active.png" or ""), "industrialtest_machine_block.png"..(config.customRightTexture and "^industrialtest_"..config.name.."_right_active.png" or ""), "industrialtest_machine_block.png"..(config.customLeftTexture and "^industrialtest_"..config.name.."_left_active.png" or ""), "industrialtest_machine_block.png"..(config.customBackTexture and "^industrialtest_"..config.name.."_back_active.png" or ""), "industrialtest_machine_block.png"..(config.customFrontTexture and "^industrialtest_"..config.name.."_front_active.png" or "") } definition.on_timer=function(pos,elapsed) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) local powerStorageSlot=inv:get_stack("powerStorage",1) local shouldUpdateFormspec=false local shouldRerunTimer=false local requiredPower=elapsed*config.opPower if powerStorageSlot:get_count()>0 then local stackMeta=powerStorageSlot:get_meta() if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then shouldUpdateFormspec=true shouldRerunTimer=true industrialtest.api.updateItemPowerText(powerStorageSlot) inv:set_stack("powerStorage",1,powerStorageSlot) end end if srcSlot:get_count()>0 and meta:get_float("maxSrcTime")<=0 and meta:get_int("industrialtest.powerAmount")>=requiredPower then local output=craftResultProxy(config.method,srcSlot) if output.time>0 and inv:room_for_item("dst",output.item) then meta:set_float("srcTime",0) meta:set_float("maxSrcTime",output.time*config.efficiency) end end if srcSlot:get_count()==0 and meta:get_float("maxSrcTime")>0 then meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) shouldUpdateFormspec=true end if meta:get_float("maxSrcTime")>0 then if meta:get_int("industrialtest.powerAmount")>=requiredPower then meta:set_int("industrialtest.powerAmount",meta:get_int("industrialtest.powerAmount")-requiredPower) meta:set_float("srcTime",meta:get_float("srcTime")+elapsed) shouldRerunTimer=true end shouldUpdateFormspec=true end if meta:get_float("maxSrcTime")<=0 or meta:get_int("industrialtest.powerAmount")=meta:get_float("maxSrcTime") then local output=craftResultProxy(config.method,srcSlot) if output.item:get_count()>0 then inv:add_item("dst",output.item) meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) end inv:set_stack("src",1,output.src) end if not industrialtest.api.isFullyCharged(meta) then industrialtest.api.triggerNeighbours(pos) end if shouldUpdateFormspec then meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) end return shouldRerunTimer end if industrialtest.mclAvailable then definition.groups.not_in_creative_inventory=1 definition._doc_items_create_entry=false end minetest.register_node("industrialtest:"..config.name.."_active",definition) end local function ironFurnaceFormspec(fuelPercent,srcPercent) local formspec if industrialtest.mtgAvailable then formspec={ "formspec_version[4]", "size[10.8,12]", "label[0.5,0.5;"..S("Iron Furnace").."]", "list[context;src;3.4,1.8;1,1]", "listring[context;src]", (fuelPercent>0 and "image[3.4,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]" or "image[3.4,2.8;1,1;default_furnace_fire_bg.png]"), "list[context;fuel;3.4,3.9;1,1]", "listring[context;fuel]", (srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]" or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"), "list[context;dst;6.4,2.8;1,1]", "listring[context;dst]", "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("Iron Furnace").."]", "list[context;src;3.4,1.8;1,1]", mcl_formspec.get_itemslot_bg(3.4,1.8,1,1), "listring[context;src]", (fuelPercent>0 and "image[3.4,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]" or "image[3.4,2.8;1,1;default_furnace_fire_bg.png]"), "list[context;fuel;3.4,3.9;1,1]", mcl_formspec.get_itemslot_bg(3.4,3.9,1,1), "listring[context;fuel]", (srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]" or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"), "list[context;dst;6.4,2.8;1,1]", mcl_formspec.get_itemslot_bg(6.4,2.8,1,1), "listring[context;dst]", "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("Iron Furnace"), 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_iron_furnace_front.png", "industrialtest_machine_block.png" }, paramtype2="facedir", legacy_facedir_simple=true, on_construct=function(pos,placer) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() inv:set_size("src",1) inv:set_size("dst",1) inv:set_size("fuel",1) meta:set_string("formspec",ironFurnaceFormspec(0,0)) meta:set_float("fuelTime",0) meta:set_float("maxFuelTime",1) meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end, on_timer=function(pos,elapsed) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) local fuelSlot=inv:get_stack("fuel",1) local shouldUpdateFormspec=false local shouldRerunTimer=false if fuelSlot:get_count()>0 and meta:get_float("fuelTime")<=0 then local output,after=minetest.get_craft_result({ method="cooking", width=1, items={srcSlot} }) if output.time>0 and inv:room_for_item("dst",output.item) then output,after=minetest.get_craft_result({ method="fuel", width=1, items={fuelSlot} }) if output.time>0 then meta:set_float("fuelTime",output.time) meta:set_float("maxFuelTime",output.time) inv:set_stack("fuel",1,after.items[1]) minetest.swap_node(pos,{ name="industrialtest:iron_furnace_active", param2=minetest.get_node(pos).param2 }) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end end end if shouldUpdateFormspec then meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) end return shouldRerunTimer end, allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count,player) if toList=="dst" then return 0 end return count end, allow_metadata_inventory_put=function(pos,listname,index,stack) if listname=="dst" then return 0 elseif listname=="src" then local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) if srcSlot:get_name()~=stack:get_name() then meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) end end return stack:get_count() end, on_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) local dstSlot=inv:get_stack("dst",1) if fromList=="src" and count==srcSlot:get_count() then meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) if meta:get_float("maxFuelTime")>0 then meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0)) end elseif fromList=="dst" and dstSlot:get_free_space()==0 then minetest.get_node_timer(pos):start(industrialtest.updateDelay) end end, on_metadata_inventory_put=function(pos,listname,index,stack) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end, on_metadata_inventory_take=function(pos,listname,index,stack) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) local dstSlot=inv:get_stack("dst",1) if listname=="src" and stack:get_count()==srcSlot:get_count() then meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) if meta:get_float("maxFuelTime")>0 then meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0)) end elseif listname=="dst" and dstSlot:get_free_space()==0 then minetest.get_node_timer(pos):start(industrialtest.updateDelay) end 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("src")[1]:get_count()>0 or inv:get_list("fuel")[1]:get_count()>0 or inv:get_list("dst")[1]:get_count()>0) end elseif industrialtest.mclAvailable then definition.after_dig_node=function(pos,oldnode,oldmeta) mclAfterDigNode(pos,oldmeta,{"src","fuel","dst"}) end definition.sounds=mcl_sounds.node_sound_metal_defaults() definition._mcl_blast_resistance=3 definition._mcl_hardness=3.5 end minetest.register_node("industrialtest:iron_furnace",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_iron_furnace_front_active.png", "industrialtest_machine_block.png" } definition.light_source=8 definition.drop="industrialtest:iron_furnace" definition.on_timer=function(pos,elapsed) local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local srcSlot=inv:get_stack("src",1) local fuelSlot=inv:get_stack("fuel",1) local shouldUpdateFormspec=false local shouldRerunTimer=false if fuelSlot:get_count()>0 and meta:get_float("fuelTime")<=0 then local output,after=minetest.get_craft_result({ method="cooking", width=1, items={srcSlot} }) if output.time>0 and inv:room_for_item("dst",output.item) then output,after=minetest.get_craft_result({ method="fuel", width=1, items={fuelSlot} }) if output.time>0 then meta:set_float("fuelTime",output.time) meta:set_float("maxFuelTime",output.time) inv:set_stack("fuel",1,after.items[1]) end end end if srcSlot:get_count()>0 and meta:get_float("maxSrcTime")<=0 and meta:get_float("fuelTime")>0 then local output,after=minetest.get_craft_result({ method="cooking", width=1, items={srcSlot} }) if output.time>0 and inv:room_for_item("dst",output.item) then meta:set_float("srcTime",0) meta:set_float("maxSrcTime",output.time*0.7) end end if meta:get_float("fuelTime")>0 then meta:set_float("fuelTime",meta:get_float("fuelTime")-elapsed) shouldUpdateFormspec=true shouldRerunTimer=true end if meta:get_float("maxSrcTime")>0 then if meta:get_float("fuelTime")>0 then meta:set_float("srcTime",meta:get_float("srcTime")+elapsed) else meta:set_float("srcTime",0) minetest.swap_node(pos,{ name="industrialtest:iron_furnace", param2=minetest.get_node(pos).param2 }) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end shouldUpdateFormspec=true shouldRerunTimer=true else minetest.swap_node(pos,{ name="industrialtest:iron_furnace", param2=minetest.get_node(pos).param2 }) minetest.get_node_timer(pos):start(industrialtest.updateDelay) end if meta:get_float("srcTime")>=meta:get_float("maxSrcTime") then local output,after=minetest.get_craft_result({ method="cooking", width=1, items={srcSlot} }) if output.item:get_count()>0 then inv:set_stack("src",1,after.items[1]) inv:add_item("dst",output.item) meta:set_float("srcTime",-1) meta:set_float("maxSrcTime",0) end end if shouldUpdateFormspec then meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) end return shouldRerunTimer end if industrialtest.mclAvailable then definition.groups={ not_in_creative_inventory=1 } definition._doc_items_create_entry=false end minetest.register_node("industrialtest:iron_furnace_active",definition) minetest.register_craft({ type="shaped", output="industrialtest:iron_furnace", recipe={ {industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot}, {industrialtest.elementKeys.ironIngot,"",industrialtest.elementKeys.ironIngot}, {industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot} } }) minetest.register_craft({ type="shaped", output="industrialtest:iron_furnace", recipe={ {"",industrialtest.elementKeys.ironIngot,""}, {industrialtest.elementKeys.ironIngot,"",industrialtest.elementKeys.ironIngot}, {industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.furnace,industrialtest.elementKeys.ironIngot} } }) registerSimpleElectricItemProcessor({ name="electric_furnace", displayName="Electric Furnace", customFrontTexture=true, capacity=416, flow=industrialtest.api.lvPowerFlow, opPower=60, method="cooking", efficiency=0.5 }) minetest.register_craft({ type="shaped", output="industrialtest:electric_furnace", recipe={ {"","industrialtest:electronic_circuit",""}, {industrialtest.elementKeys.powerCarrier,"industrialtest:iron_furnace",industrialtest.elementKeys.powerCarrier} } }) registerSimpleElectricItemProcessor({ name="macerator", displayName="Macerator", customFrontTexture=true, requiresWrench=true, capacity=1200, flow=industrialtest.api.lvPowerFlow, opPower=100, method="industrialtest.macerating", efficiency=1 }) minetest.register_craft({ type="shaped", output="industrialtest:macerator", recipe={ {industrialtest.elementKeys.flint,industrialtest.elementKeys.flint,industrialtest.elementKeys.flint}, {industrialtest.elementKeys.cobble,"industrialtest:machine_block",industrialtest.elementKeys.cobble}, {"","industrialtest:electronic_circuit",""} } }) registerSimpleElectricItemProcessor({ name="compressor", displayName="Compressor", customFrontTexture=true, requiresWrench=true, capacity=1400, flow=industrialtest.api.lvPowerFlow, opPower=120, method="industrialtest.compressing", efficiency=1 }) minetest.register_craft({ type="shaped", output="industrialtest:compressor", recipe={ {industrialtest.elementKeys.stone,"",industrialtest.elementKeys.stone}, {industrialtest.elementKeys.stone,"industrialtest:machine_block",industrialtest.elementKeys.stone}, {industrialtest.elementKeys.stone,"industrialtest:electronic_circuit",industrialtest.elementKeys.stone} } }) registerSimpleElectricItemProcessor({ name="extractor", displayName="Extractor", customFrontTexture=true, requiresWrench=true, capacity=900, flow=industrialtest.api.lvPowerFlow, 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"} } }) registerSimpleElectricItemProcessor({ name="recycler", displayName="Recycler", customTopTexture=true, requiresWrench=true, capacity=80, flow=industrialtest.api.lvPowerFlow, opPower=40, method="industrialtest.recycling", efficiency=1 }) minetest.register_craft({ type="shaped", output="industrialtest:recycler", recipe={ {"",industrialtest.elementKeys.glowstone,""}, {industrialtest.elementKeys.dirt,"industrialtest:compressor",industrialtest.elementKeys.dirt}, {"industrialtest:refined_iron_ingot",industrialtest.elementKeys.dirt,"industrialtest:refined_iron_ingot"} } }) -- Transformers local function registerTransformer(config) definition={ description=S(config.displayName), tiles={ config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png", config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png", config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png", config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png", config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png", config.machineBlockTexture.."^industrialtest_"..config.name.."_front.png" }, paramtype2="facedir", legacy_facedir_simple=true, drop=(config.requiresWrench and "industrialtest:machine_block" or "industrialtest:"..config.name), on_construct=function(pos) local meta=minetest.get_meta(pos) industrialtest.api.addPowerStorage(meta,config.upperFlow,0,"aaaaaa") end, on_timer=function(pos,elapsed) local meta=minetest.get_meta(pos) local node=minetest.get_node(pos) local neighbourPositions={ vector.offset(pos,-1,0,0), vector.offset(pos,1,0,0), vector.offset(pos,0,-1,0), vector.offset(pos,0,1,0), vector.offset(pos,0,0,-1), vector.offset(pos,0,0,1) } local upperPowerDistribution=0 local lowerPowerDistribution=0 for key,value in ipairs(neighbourPositions) do local normalized=industrialtest.api.normalizeSide(pos,key) if industrialtest.api.hasPowerStorage(minetest.get_meta(value)) and industrialtest.api.isPowerOutput(meta,normalized) then if normalized==5 then upperPowerDistribution=config.upperFlow else lowerPowerDistribution=lowerPowerDistribution+1 end else neighbourPositions[key]=0 end end if lowerPowerDistribution>0 then lowerPowerDistribution=math.floor(industrialtest.internal.clamp(math.min(config.upperFlow,meta:get_int("industrialtest.powerAmount"))/lowerPowerDistribution,0,config.lowerFlow)) end local roomAvailable=false for key,value in ipairs(neighbourPositions) do if value~=0 then local neighbourMeta=minetest.get_meta(value) local normalized=industrialtest.api.normalizeSide(pos,key) if normalized==5 then if meta:get_int("industrialtest.powerAmount")==config.upperFlow then industrialtest.api.transferPower(meta,neighbourMeta,config.upperFlow) end else industrialtest.api.transferPower(meta,neighbourMeta,lowerPowerDistribution) end if not industrialtest.api.isFullyCharged(neighbourMeta) then roomAvailable=true end end end meta:set_string("industrialtest.ioConfig","aaaaaa") return (meta:get_int("industrialtest.powerAmount")>0 and roomAvailable) end, _industrialtest_onPowerFlow=function(pos,side) industrialtest.api.changeIoConfig(minetest.get_meta(pos),industrialtest.api.normalizeSide(pos,side),"i") minetest.get_node_timer(pos):start(industrialtest.updateDelay) end } if industrialtest.mtgAvailable then definition.groups={cracky=2} definition.sounds=(config.sounds=="metal" and default.node_sound_metal_defaults() or default.node_sound_wood_defaults()) elseif industrialtest.mclAvailable then definition.groups={pickaxey=1} definition.sounds=(config.sounds=="metal" and mcl_sounds.node_sound_metal_defaults() or mcl_sounds.node_sound_wood_defaults()) definition._mcl_blast_resistance=3 definition._mcl_hardness=3.5 end definition.groups._industrialtest_hasPowerInput=1 definition.groups._industrialtest_hasPowerOutput=1 definition.groups._industrialtest_wrenchUnmountable=1 minetest.register_node("industrialtest:"..config.name,definition) end registerTransformer({ name="lv_transformer", displayName="LV Transformer", machineBlockTexture="industrialtest_wood_machine_block.png", requiresWrench=false, lowerFlow=industrialtest.api.lvPowerFlow, upperFlow=industrialtest.api.mvPowerFlow, sounds="wood" }) minetest.register_craft({ type="shaped", output="industrialtest:lv_transformer", recipe={ {"group:wood","industrialtest:insulated_tin_cable","group:wood"}, {industrialtest.elementKeys.copperIngot,industrialtest.elementKeys.copperIngot,industrialtest.elementKeys.copperIngot}, {"group:wood","industrialtest:insulated_copper_cable","group:wood"} } }) registerTransformer({ name="mv_transformer", displayName="MV Transformer", machineBlockTexture="industrialtest_machine_block.png", requiresWrench=true, lowerFlow=industrialtest.api.mvPowerFlow, upperFlow=industrialtest.api.hvPowerFlow, sounds="metal" }) minetest.register_craft({ type="shaped", output="industrialtest:mv_transformer", recipe={ {"industrialtest:insulated_copper_cable"}, {"industrialtest:machine_block"}, {"industrialtest:insulated_gold_cable"} } }) registerTransformer({ name="hv_transformer", displayName="HV Transformer", machineBlockTexture="industrialtest_machine_block.png", requiresWrench=true, lowerFlow=industrialtest.api.hvPowerFlow, upperFlow=industrialtest.api.evPowerFlow, sounds="metal" }) -- TODO: Craft for HV transformer registerTransformer({ name="ev_transformer", displayName="EV Transformer", machineBlockTexture="industrialtest_machine_block.png", requiresWrench=true, lowerFlow=industrialtest.api.evPowerFlow, upperFlow=industrialtest.api.ivPowerFlow, sounds="metal" }) -- TODO: Craft for EV Transformer