Implement Water Mill

This commit is contained in:
mrkubax10 2023-04-02 18:07:56 +02:00
parent 35d78037c0
commit 156cca1b66
7 changed files with 388 additions and 234 deletions

33
api.lua
View File

@ -21,6 +21,7 @@ industrialtest.api.maceratorRecipes={}
industrialtest.api.compressorRecipes={} industrialtest.api.compressorRecipes={}
industrialtest.api.extractorRecipes={} industrialtest.api.extractorRecipes={}
industrialtest.api.geothermalGeneratorFuels={} industrialtest.api.geothermalGeneratorFuels={}
industrialtest.api.waterMillFuels={}
industrialtest.api.lvPowerFlow=600 industrialtest.api.lvPowerFlow=600
industrialtest.api.mvPowerFlow=2400 industrialtest.api.mvPowerFlow=2400
@ -441,3 +442,35 @@ industrialtest.api.getGeothermalGeneratorFuelByItem=function(name)
end end
return nil return nil
end end
-- \brief Registers fuel that can be used in water mill
-- \param fuel Table with following keys: <name>, <calorificValue>, <storageItems>
-- which is a table containing items which are tables with following keys: <name>, <leftover>
-- \returns nil
industrialtest.api.registerWaterMillFuel=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.waterMillFuels[definition.name]=definition
end
-- \brief Returns water mill fuel information
-- \param name Name of fuel
-- \returns Table with following keys: name, calorificValue, storageItems
industrialtest.api.getWaterMillFuel=function(name)
return industrialtest.api.waterMillFuels[name]
end
-- \brief Returns water mill 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.getWaterMillFuelByItem=function(name)
for _,value in pairs(industrialtest.api.waterMillFuels) do
for _,item in ipairs(value.storageItems) do
if item.name==name then
return value
end
end
end
return nil
end

View File

@ -502,6 +502,7 @@ if industrialtest.mclAvailable then
industrialtest.elementKeys.diamond="mcl_core:diamond" industrialtest.elementKeys.diamond="mcl_core:diamond"
industrialtest.elementKeys.bucket="mcl_buckets:bucket_empty" industrialtest.elementKeys.bucket="mcl_buckets:bucket_empty"
industrialtest.elementKeys.bucketWithLava="mcl_buckets:bucket_lava" industrialtest.elementKeys.bucketWithLava="mcl_buckets:bucket_lava"
industrialtest.elementKeys.bucketWithWater="mcl_buckets:bucket_water"
industrialtest.elementKeys.glowstone="mcl_nether:glowstone_dust" industrialtest.elementKeys.glowstone="mcl_nether:glowstone_dust"
industrialtest.elementKeys.glass="mcl_core:glass" industrialtest.elementKeys.glass="mcl_core:glass"
industrialtest.elementKeys.powerCarrier="mesecons:mesecon" industrialtest.elementKeys.powerCarrier="mesecons:mesecon"
@ -527,6 +528,7 @@ if industrialtest.mclAvailable then
industrialtest.elementKeys.copperBlock="mcl_copper:block" industrialtest.elementKeys.copperBlock="mcl_copper:block"
industrialtest.elementKeys.stoneWithCopper="mcl_copper:stone_with_copper" industrialtest.elementKeys.stoneWithCopper="mcl_copper:stone_with_copper"
industrialtest.elementKeys.lavaSource="mcl_core:lava_source" industrialtest.elementKeys.lavaSource="mcl_core:lava_source"
industrialtest.elementKeys.waterSource="mcl_core:water_source"
-- register required minerals that are not available in MCL -- register required minerals that are not available in MCL
industrialtest.registerMetal("tin","Tin",3,3) industrialtest.registerMetal("tin","Tin",3,3)
@ -706,6 +708,7 @@ elseif industrialtest.mtgAvailable then
industrialtest.elementKeys.snowball="default:snow" industrialtest.elementKeys.snowball="default:snow"
industrialtest.elementKeys.bucket="bucket:bucket_empty" industrialtest.elementKeys.bucket="bucket:bucket_empty"
industrialtest.elementKeys.bucketWithLava="bucket:bucket_lava" industrialtest.elementKeys.bucketWithLava="bucket:bucket_lava"
industrialtest.elementKeys.bucketWithWater="bucket:bucket_water"
industrialtest.elementKeys.string="farming:string" industrialtest.elementKeys.string="farming:string"
industrialtest.elementKeys.junglePlanks="default:junglewood" industrialtest.elementKeys.junglePlanks="default:junglewood"
industrialtest.elementKeys.glowstone="dye:yellow" industrialtest.elementKeys.glowstone="dye:yellow"
@ -736,6 +739,7 @@ elseif industrialtest.mtgAvailable then
industrialtest.elementKeys.stoneWithTin="default:stone_with_tin" industrialtest.elementKeys.stoneWithTin="default:stone_with_tin"
industrialtest.elementKeys.bronzeBlock="default:bronzeblock" industrialtest.elementKeys.bronzeBlock="default:bronzeblock"
industrialtest.elementKeys.lavaSource="default:lava_source" industrialtest.elementKeys.lavaSource="default:lava_source"
industrialtest.elementKeys.waterSource="default:water_source"
else else
error("No compatible games found!") error("No compatible games found!")
end end

View File

@ -87,3 +87,29 @@ industrialtest.api.registerGeothermalGeneratorFuel({
} }
} }
}) })
-- Water Mill fuels
industrialtest.api.registerWaterMillFuel({
name=industrialtest.elementKeys.waterSource,
calorificValue=industrialtest.api.lvPowerFlow,
texture="industrialtest_gui_water.png",
storageItems={
{
name=industrialtest.elementKeys.bucketWithWater,
leftover=industrialtest.elementKeys.bucket
}
}
})
if industrialtest.mtgAvailable then
industrialtest.api.registerWaterMillFuel({
name="default:river_water_source",
calorificValue=industrialtest.api.lvPowerFlow,
texture="industrialtest_gui_river_water.png",
storageItems={
{
name="bucket:bucket_river_water",
leftover=industrialtest.elementKeys.bucket
}
}
})
end

View File

@ -447,15 +447,16 @@ minetest.register_craft({
} }
}) })
local function geothermalGeneratorFormspec(fluidPercent,powerPercent,fluid) local function registerFluidGenerator(config)
local function getFormspec(fluidPercent,powerPercent,fluid)
local formspec local formspec
local fuel=industrialtest.api.getGeothermalGeneratorFuel(fluid) local fuel=config.getFuel(fluid)
local tile=(fuel and fuel.texture or "industrialtest_gui_fluid_bg.png") local tile=(fuel and fuel.texture or "industrialtest_gui_fluid_bg.png")
if industrialtest.mtgAvailable then if industrialtest.mtgAvailable then
formspec={ formspec={
"formspec_version[4]", "formspec_version[4]",
"size[10.8,12]", "size[10.8,12]",
"label[0.5,0.5;"..S("Geothermal Generator").."]", "label[0.5,0.5;"..S(config.displayName).."]",
"list[context;fluid;2,1.8;1,1]", "list[context;fluid;2,1.8;1,1]",
"listring[context;fluid]", "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]"), (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]"),
@ -470,7 +471,7 @@ local function geothermalGeneratorFormspec(fluidPercent,powerPercent,fluid)
elseif industrialtest.mclAvailable then elseif industrialtest.mclAvailable then
formspec={ formspec={
"size[10.04,12]", "size[10.04,12]",
"label[0.25,0.25;"..S("Geothermal Generator").."]", "label[0.25,0.25;"..S(config.displayName).."]",
"list[context;fluid;2,1.8;1,1]", "list[context;fluid;2,1.8;1,1]",
mcl_formspec.get_itemslot_bg(2,1.8,1,1), mcl_formspec.get_itemslot_bg(2,1.8,1,1),
"listring[context;fluid]", "listring[context;fluid]",
@ -490,16 +491,16 @@ local function geothermalGeneratorFormspec(fluidPercent,powerPercent,fluid)
} }
end end
return table.concat(formspec,"") return table.concat(formspec,"")
end end
definition={ definition={
description=S("Geothermal Generator"), description=S(config.displayName),
tiles={ tiles={
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customTopTexture and "^"..config.customTopTexture or ""),
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customBottomTexture and "^"..config.customBottomTexture or ""),
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customRightTexture and "^"..config.customRightTexture or ""),
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customLeftTexture and "^"..config.customLeftTexture or ""),
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customBackTexture and "^"..config.customBackTexture or ""),
"industrialtest_machine_block.png^industrialtest_geothermal_generator_front.png", "industrialtest_machine_block.png"..(config.customFrontTexture and "^"..config.customFrontTexture or "")
}, },
paramtype2="facedir", paramtype2="facedir",
legacy_facedir_simple=true, legacy_facedir_simple=true,
@ -512,7 +513,7 @@ definition={
inv:set_size("leftover",1) inv:set_size("leftover",1)
meta:set_float("fluidAmount",0) meta:set_float("fluidAmount",0)
meta:set_string("fluid","") meta:set_string("fluid","")
meta:set_string("formspec",geothermalGeneratorFormspec(0,0,"")) meta:set_string("formspec",getFormspec(0,0,""))
industrialtest.api.addPowerStorage(meta,7000,industrialtest.api.lvPowerFlow,"oooooo") industrialtest.api.addPowerStorage(meta,7000,industrialtest.api.lvPowerFlow,"oooooo")
end, end,
on_timer=function(pos,elapsed) on_timer=function(pos,elapsed)
@ -525,7 +526,7 @@ definition={
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0) local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then
local fuel=industrialtest.api.getGeothermalGeneratorFuelByItem(fluidSlot:get_name()) local fuel=config.getFuelByItem(fluidSlot:get_name())
if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then
local leftover=false local leftover=false
local leftoverAddingSucceeded=false local leftoverAddingSucceeded=false
@ -550,14 +551,18 @@ definition={
end end
if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then
meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed) meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed)
local toAdd=math.ceil(industrialtest.api.getGeothermalGeneratorFuel(meta:get_string("fluid")).calorificValue*elapsed) local toAdd=math.ceil(config.getFuel(meta:get_string("fluid")).calorificValue*elapsed)
industrialtest.api.addPower(meta,toAdd) industrialtest.api.addPower(meta,toAdd)
shouldUpdateFormspec=true shouldUpdateFormspec=true
if config.registerActiveVariant then
minetest.swap_node(pos,{ minetest.swap_node(pos,{
name="industrialtest:geothermal_generator_active", name="industrialtest:"..config.name.."_active",
param2=minetest.get_node(pos).param2 param2=minetest.get_node(pos).param2
}) })
minetest.get_node_timer(pos):start(industrialtest.updateDelay) minetest.get_node_timer(pos):start(industrialtest.updateDelay)
else
shouldRerunTimer=true
end
end end
if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 then if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 then
if industrialtest.api.transferPowerToItem(meta,chargedSlot,industrialtest.api.lvPowerFlow)>0 then if industrialtest.api.transferPowerToItem(meta,chargedSlot,industrialtest.api.lvPowerFlow)>0 then
@ -566,9 +571,12 @@ definition={
shouldRerunTimer=true shouldRerunTimer=true
end end
end end
if flowTransferred then
shouldUpdateFormspec=true
end
if shouldUpdateFormspec then 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"))) meta:set_string("formspec",getFormspec(meta:get_float("fluidAmount")/100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"),meta:get_string("fluid")))
end end
return shouldRerunTimer return shouldRerunTimer
@ -595,10 +603,10 @@ definition={
minetest.get_node_timer(pos):start(industrialtest.updateDelay) minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end, end,
_industrialtest_updateFormspec=function(meta) _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"))) meta:set_string("formspec",getFormspec(meta:get_float("fluidAmount")/100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"),meta:get_string("fluid")))
end end
} }
if industrialtest.mtgAvailable then if industrialtest.mtgAvailable then
definition.groups={ definition.groups={
cracky=1, cracky=1,
level=2 level=2
@ -609,7 +617,7 @@ if industrialtest.mtgAvailable then
local inv=meta:get_inventory() local inv=meta:get_inventory()
return not (inv:get_list("charged")[1]:get_count()>0 or inv:get_list("fluid")[1]:get_count()>0) return not (inv:get_list("charged")[1]:get_count()>0 or inv:get_list("fluid")[1]:get_count()>0)
end end
elseif industrialtest.mclAvailable then elseif industrialtest.mclAvailable then
definition.after_dig_node=function(pos,oldnode,oldmeta) definition.after_dig_node=function(pos,oldnode,oldmeta)
mclAfterDigNode(pos,oldmeta,{"charged","fluid"}) mclAfterDigNode(pos,oldmeta,{"charged","fluid"})
end end
@ -617,21 +625,22 @@ elseif industrialtest.mclAvailable then
definition.sounds=mcl_sounds.node_sound_metal_defaults() definition.sounds=mcl_sounds.node_sound_metal_defaults()
definition._mcl_blast_resistance=3 definition._mcl_blast_resistance=3
definition._mcl_hardness=3.5 definition._mcl_hardness=3.5
end end
definition.groups._industrialtest_hasPowerOutput=1 definition.groups._industrialtest_hasPowerOutput=1
definition.groups._industrialtest_wrenchUnmountable=1 definition.groups._industrialtest_wrenchUnmountable=1
minetest.register_node("industrialtest:geothermal_generator",definition) minetest.register_node("industrialtest:"..config.name,definition)
definition=table.copy(definition) if config.registerActiveVariant then
definition.description=nil definition=table.copy(definition)
definition.tiles={ definition.description=nil
"industrialtest_machine_block.png", definition.tiles={
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customTopTexture and "^"..config.customTopTextureActive or ""),
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customBottomTexture and "^"..config.customBottomTextureActive or ""),
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customRightTexture and "^"..config.customRightTextureActive or ""),
"industrialtest_machine_block.png", "industrialtest_machine_block.png"..(config.customLeftTexture and "^"..config.customLeftTextureActive or ""),
"industrialtest_machine_block.png^industrialtest_geothermal_generator_front_active.png", "industrialtest_machine_block.png"..(config.customBackTexture and "^"..config.customBackTextureActive or ""),
} "industrialtest_machine_block.png"..(config.customFrontTexture and "^"..config.customFrontTextureActive or "")
definition.on_timer=function(pos,elapsed) }
definition.on_timer=function(pos,elapsed)
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
local fluidSlot=inv:get_stack("fluid",1) local fluidSlot=inv:get_stack("fluid",1)
@ -641,7 +650,7 @@ definition.on_timer=function(pos,elapsed)
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0) local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then
local fuel=industrialtest.api.getGeothermalGeneratorFuelByItem(fluidSlot:get_name()) local fuel=config.getFuelByItem(fluidSlot:get_name())
if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then
local leftover=false local leftover=false
local leftoverAddingSucceeded=false local leftoverAddingSucceeded=false
@ -673,7 +682,7 @@ definition.on_timer=function(pos,elapsed)
shouldRerunTimer=true shouldRerunTimer=true
else else
minetest.swap_node(pos,{ minetest.swap_node(pos,{
name="industrialtest:geothermal_generator", name="industrialtest:"..config.name,
param2=minetest.get_node(pos).param2 param2=minetest.get_node(pos).param2
}) })
minetest.get_node_timer(pos):start(industrialtest.updateDelay) minetest.get_node_timer(pos):start(industrialtest.updateDelay)
@ -685,19 +694,99 @@ definition.on_timer=function(pos,elapsed)
shouldRerunTimer=true shouldRerunTimer=true
end end
end end
if flowTransferred then
shouldUpdateFormspec=true
end
if shouldUpdateFormspec then 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"))) meta:set_string("formspec",getFormspec(meta:get_float("fluidAmount")/100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity"),meta:get_string("fluid")))
end end
return shouldRerunTimer return shouldRerunTimer
end end
if industrialtest.mclAvailable then if industrialtest.mclAvailable then
definition.groups.not_in_creative_inventory=1 definition.groups.not_in_creative_inventory=1
definition._doc_items_create_entry=false definition._doc_items_create_entry=false
end
definition.light_source=8
minetest.register_node("industrialtest:"..config.name.."_active",definition)
end
end end
definition.light_source=8
minetest.register_node("industrialtest:geothermal_generator_active",definition) registerFluidGenerator({
name="geothermal_generator",
displayName="Geothermal Generator",
customFrontTexture="industrialtest_geothermal_generator_front.png",
customFrontTextureActive="industrialtest_geothermal_generator_front_active.png",
getFuel=industrialtest.api.getGeothermalGeneratorFuel,
getFuelByItem=industrialtest.api.getGeothermalGeneratorFuelByItem,
registerActiveVariant=true,
reactsToNeighbouringNodes=false
})
registerFluidGenerator({
name="water_mill",
displayName="Water Mill",
customLeftTexture="industrialtest_water_mill_side.png",
customRightTexture="industrialtest_water_mill_side.png",
customFrontTexture="industrialtest_water_mill_side.png",
customBackTexture="industrialtest_water_mill_side.png",
getFuel=industrialtest.api.getWaterMillFuel,
getFuelByItem=industrialtest.api.getWaterMillFuelByItem,
registerActiveVariant=false
})
local neighbors={}
for key,_ in pairs(industrialtest.api.waterMillFuels) do
table.insert(neighbors,key)
end
minetest.register_abm({
label="Water Mill generating",
nodenames={"industrialtest:water_mill"},
neighbors=neighbors,
interval=industrialtest.updateDelay,
chance=1,
action=function(pos,node)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local chargedSlot=inv:get_stack("charged",1)
local powerToAdd=0
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)
}
for _,value in ipairs(neighbourPositions) do
local node=minetest.get_node_or_nil(value)
if node then
local fuel=industrialtest.api.getWaterMillFuel(node.name)
if fuel then
powerToAdd=powerToAdd+fuel.calorificValue*0.2
end
end
end
if industrialtest.api.addPower(meta,powerToAdd)>0 then
local def=minetest.registered_nodes[node.name]
def._industrialtest_updateFormspec(meta)
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)
end
end
end
})
minetest.register_craft({
type="shaped",
output="industrialtest:water_mill",
recipe={
{"",industrialtest.elementKeys.stick,""},
{industrialtest.elementKeys.stick,"industrialtest:generator",industrialtest.elementKeys.stick},
{"",industrialtest.elementKeys.stick,""}
}
})
-- Item processing machines -- Item processing machines
local function registerSimpleElectricItemProcessor(config) local function registerSimpleElectricItemProcessor(config)

View File

@ -1,4 +1,6 @@
# Texture sources # Texture sources
- `industrialtest_gui_lava.png` was taken from Minetest Game (by Cisoun licensed with CC BY-SA 3.0) - `industrialtest_gui_lava.png` was taken from Minetest Game (by Cisoun licensed with CC BY-SA 3.0)
- `industrialtest_gui_water.png` was taken from Minetest Game (by Cisoun licensed with CC BY-SA 3.0)
- `industrialtest_gui_river_water.png` was taken from Minetest Game (by paramat licensed with CC BY-SA 3.0)
... rest was made either by LuanHawk, mrkubax10 or Migdyn and is licensed with CC BY 4.0 International ... rest was made either by LuanHawk, mrkubax10 or Migdyn and is licensed with CC BY 4.0 International

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B