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.extractorRecipes={}
industrialtest.api.geothermalGeneratorFuels={}
industrialtest.api.waterMillFuels={}
industrialtest.api.lvPowerFlow=600
industrialtest.api.mvPowerFlow=2400
@ -441,3 +442,35 @@ industrialtest.api.getGeothermalGeneratorFuelByItem=function(name)
end
return nil
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.bucket="mcl_buckets:bucket_empty"
industrialtest.elementKeys.bucketWithLava="mcl_buckets:bucket_lava"
industrialtest.elementKeys.bucketWithWater="mcl_buckets:bucket_water"
industrialtest.elementKeys.glowstone="mcl_nether:glowstone_dust"
industrialtest.elementKeys.glass="mcl_core:glass"
industrialtest.elementKeys.powerCarrier="mesecons:mesecon"
@ -527,6 +528,7 @@ if industrialtest.mclAvailable then
industrialtest.elementKeys.copperBlock="mcl_copper:block"
industrialtest.elementKeys.stoneWithCopper="mcl_copper:stone_with_copper"
industrialtest.elementKeys.lavaSource="mcl_core:lava_source"
industrialtest.elementKeys.waterSource="mcl_core:water_source"
-- register required minerals that are not available in MCL
industrialtest.registerMetal("tin","Tin",3,3)
@ -706,6 +708,7 @@ elseif industrialtest.mtgAvailable then
industrialtest.elementKeys.snowball="default:snow"
industrialtest.elementKeys.bucket="bucket:bucket_empty"
industrialtest.elementKeys.bucketWithLava="bucket:bucket_lava"
industrialtest.elementKeys.bucketWithWater="bucket:bucket_water"
industrialtest.elementKeys.string="farming:string"
industrialtest.elementKeys.junglePlanks="default:junglewood"
industrialtest.elementKeys.glowstone="dye:yellow"
@ -736,6 +739,7 @@ elseif industrialtest.mtgAvailable then
industrialtest.elementKeys.stoneWithTin="default:stone_with_tin"
industrialtest.elementKeys.bronzeBlock="default:bronzeblock"
industrialtest.elementKeys.lavaSource="default:lava_source"
industrialtest.elementKeys.waterSource="default:water_source"
else
error("No compatible games found!")
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 fuel=industrialtest.api.getGeothermalGeneratorFuel(fluid)
local fuel=config.getFuel(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").."]",
"label[0.5,0.5;"..S(config.displayName).."]",
"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]"),
@ -470,7 +471,7 @@ local function geothermalGeneratorFormspec(fluidPercent,powerPercent,fluid)
elseif industrialtest.mclAvailable then
formspec={
"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]",
mcl_formspec.get_itemslot_bg(2,1.8,1,1),
"listring[context;fluid]",
@ -492,14 +493,14 @@ local function geothermalGeneratorFormspec(fluidPercent,powerPercent,fluid)
return table.concat(formspec,"")
end
definition={
description=S("Geothermal Generator"),
description=S(config.displayName),
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",
"industrialtest_machine_block.png"..(config.customTopTexture and "^"..config.customTopTexture or ""),
"industrialtest_machine_block.png"..(config.customBottomTexture and "^"..config.customBottomTexture or ""),
"industrialtest_machine_block.png"..(config.customRightTexture and "^"..config.customRightTexture or ""),
"industrialtest_machine_block.png"..(config.customLeftTexture and "^"..config.customLeftTexture or ""),
"industrialtest_machine_block.png"..(config.customBackTexture and "^"..config.customBackTexture or ""),
"industrialtest_machine_block.png"..(config.customFrontTexture and "^"..config.customFrontTexture or "")
},
paramtype2="facedir",
legacy_facedir_simple=true,
@ -512,7 +513,7 @@ definition={
inv:set_size("leftover",1)
meta:set_float("fluidAmount",0)
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")
end,
on_timer=function(pos,elapsed)
@ -525,7 +526,7 @@ definition={
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())
local fuel=config.getFuelByItem(fluidSlot:get_name())
if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then
local leftover=false
local leftoverAddingSucceeded=false
@ -550,14 +551,18 @@ definition={
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)
local toAdd=math.ceil(config.getFuel(meta:get_string("fluid")).calorificValue*elapsed)
industrialtest.api.addPower(meta,toAdd)
shouldUpdateFormspec=true
if config.registerActiveVariant then
minetest.swap_node(pos,{
name="industrialtest:geothermal_generator_active",
name="industrialtest:"..config.name.."_active",
param2=minetest.get_node(pos).param2
})
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
else
shouldRerunTimer=true
end
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
@ -566,9 +571,12 @@ definition={
shouldRerunTimer=true
end
end
if flowTransferred then
shouldUpdateFormspec=true
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")))
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
return shouldRerunTimer
@ -595,7 +603,7 @@ definition={
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")))
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
}
if industrialtest.mtgAvailable then
@ -620,16 +628,17 @@ elseif industrialtest.mclAvailable then
end
definition.groups._industrialtest_hasPowerOutput=1
definition.groups._industrialtest_wrenchUnmountable=1
minetest.register_node("industrialtest:geothermal_generator",definition)
minetest.register_node("industrialtest:"..config.name,definition)
if config.registerActiveVariant then
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",
"industrialtest_machine_block.png"..(config.customTopTexture and "^"..config.customTopTextureActive or ""),
"industrialtest_machine_block.png"..(config.customBottomTexture and "^"..config.customBottomTextureActive or ""),
"industrialtest_machine_block.png"..(config.customRightTexture and "^"..config.customRightTextureActive or ""),
"industrialtest_machine_block.png"..(config.customLeftTexture and "^"..config.customLeftTextureActive or ""),
"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)
local meta=minetest.get_meta(pos)
@ -641,7 +650,7 @@ definition.on_timer=function(pos,elapsed)
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())
local fuel=config.getFuelByItem(fluidSlot:get_name())
if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then
local leftover=false
local leftoverAddingSucceeded=false
@ -673,7 +682,7 @@ definition.on_timer=function(pos,elapsed)
shouldRerunTimer=true
else
minetest.swap_node(pos,{
name="industrialtest:geothermal_generator",
name="industrialtest:"..config.name,
param2=minetest.get_node(pos).param2
})
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
@ -685,9 +694,12 @@ definition.on_timer=function(pos,elapsed)
shouldRerunTimer=true
end
end
if flowTransferred then
shouldUpdateFormspec=true
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")))
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
return shouldRerunTimer
@ -697,7 +709,84 @@ if industrialtest.mclAvailable then
definition._doc_items_create_entry=false
end
definition.light_source=8
minetest.register_node("industrialtest:geothermal_generator_active",definition)
minetest.register_node("industrialtest:"..config.name.."_active",definition)
end
end
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
local function registerSimpleElectricItemProcessor(config)

View File

@ -1,4 +1,6 @@
# Texture sources
- `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

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B