Implement Water Mill
This commit is contained in:
parent
35d78037c0
commit
156cca1b66
33
api.lua
33
api.lua
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
26
crafts.lua
26
crafts.lua
|
@ -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
|
||||||
|
|
557
machines.lua
557
machines.lua
|
@ -447,257 +447,346 @@ minetest.register_craft({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
local function geothermalGeneratorFormspec(fluidPercent,powerPercent,fluid)
|
local function registerFluidGenerator(config)
|
||||||
local formspec
|
local function getFormspec(fluidPercent,powerPercent,fluid)
|
||||||
local fuel=industrialtest.api.getGeothermalGeneratorFuel(fluid)
|
local formspec
|
||||||
local tile=(fuel and fuel.texture or "industrialtest_gui_fluid_bg.png")
|
local fuel=config.getFuel(fluid)
|
||||||
if industrialtest.mtgAvailable then
|
local tile=(fuel and fuel.texture or "industrialtest_gui_fluid_bg.png")
|
||||||
formspec={
|
if industrialtest.mtgAvailable then
|
||||||
"formspec_version[4]",
|
formspec={
|
||||||
"size[10.8,12]",
|
"formspec_version[4]",
|
||||||
"label[0.5,0.5;"..S("Geothermal Generator").."]",
|
"size[10.8,12]",
|
||||||
"list[context;fluid;2,1.8;1,1]",
|
"label[0.5,0.5;"..S(config.displayName).."]",
|
||||||
"listring[context;fluid]",
|
"list[context;fluid;2,1.8;1,1]",
|
||||||
(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]"),
|
"listring[context;fluid]",
|
||||||
"list[context;leftover;2,4.2;1,1]",
|
(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]"),
|
||||||
"listring[context;leftover]",
|
"list[context;leftover;2,4.2;1,1]",
|
||||||
"list[context;charged;6,3;1,1]",
|
"listring[context;leftover]",
|
||||||
"listring[context;charged]",
|
"list[context;charged;6,3;1,1]",
|
||||||
"box[9,1;0.3,4.8;#202020]",
|
"listring[context;charged]",
|
||||||
(powerPercent>0 and "box[9,"..(1+4.8-(powerPercent*4.8))..";0.3,"..(powerPercent*4.8)..";#FF1010]" or ""),
|
"box[9,1;0.3,4.8;#202020]",
|
||||||
"list[current_player;main;0.5,6.25;8,1]list[current_player;main;0.5,7.5;8,3;8]"
|
(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={
|
elseif industrialtest.mclAvailable then
|
||||||
"size[10.04,12]",
|
formspec={
|
||||||
"label[0.25,0.25;"..S("Geothermal Generator").."]",
|
"size[10.04,12]",
|
||||||
"list[context;fluid;2,1.8;1,1]",
|
"label[0.25,0.25;"..S(config.displayName).."]",
|
||||||
mcl_formspec.get_itemslot_bg(2,1.8,1,1),
|
"list[context;fluid;2,1.8;1,1]",
|
||||||
"listring[context;fluid]",
|
mcl_formspec.get_itemslot_bg(2,1.8,1,1),
|
||||||
(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]"),
|
"listring[context;fluid]",
|
||||||
"list[context;leftover;2,4.2;1,1]",
|
(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]"),
|
||||||
mcl_formspec.get_itemslot_bg(2,4.2,1,1),
|
"list[context;leftover;2,4.2;1,1]",
|
||||||
"listring[context;leftover]",
|
mcl_formspec.get_itemslot_bg(2,4.2,1,1),
|
||||||
"list[context;charged;6,3;1,1]",
|
"listring[context;leftover]",
|
||||||
mcl_formspec.get_itemslot_bg(6,3,1,1),
|
"list[context;charged;6,3;1,1]",
|
||||||
"listring[context;charged]",
|
mcl_formspec.get_itemslot_bg(6,3,1,1),
|
||||||
"box[9,1;0.3,4.8;#202020]",
|
"listring[context;charged]",
|
||||||
(powerPercent>0 and "box[9,"..(1+4.8-(powerPercent*4.8))..";0.3,"..(powerPercent*4.8)..";#FF1010]" or ""),
|
"box[9,1;0.3,4.8;#202020]",
|
||||||
"list[current_player;main;0.5,7;9,3;9]",
|
(powerPercent>0 and "box[9,"..(1+4.8-(powerPercent*4.8))..";0.3,"..(powerPercent*4.8)..";#FF1010]" or ""),
|
||||||
mcl_formspec.get_itemslot_bg(0.5,7,9,3),
|
"list[current_player;main;0.5,7;9,3;9]",
|
||||||
"list[current_player;main;0.5,10.24;9,1]",
|
mcl_formspec.get_itemslot_bg(0.5,7,9,3),
|
||||||
mcl_formspec.get_itemslot_bg(0.5,10.24,9,1)
|
"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
|
end
|
||||||
return table.concat(formspec,"")
|
definition={
|
||||||
end
|
description=S(config.displayName),
|
||||||
definition={
|
tiles={
|
||||||
description=S("Geothermal Generator"),
|
"industrialtest_machine_block.png"..(config.customTopTexture and "^"..config.customTopTexture or ""),
|
||||||
tiles={
|
"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_machine_block.png"..(config.customFrontTexture and "^"..config.customFrontTexture or "")
|
||||||
"industrialtest_machine_block.png",
|
},
|
||||||
"industrialtest_machine_block.png^industrialtest_geothermal_generator_front.png",
|
paramtype2="facedir",
|
||||||
},
|
legacy_facedir_simple=true,
|
||||||
paramtype2="facedir",
|
drop="industrialtest:machine_block",
|
||||||
legacy_facedir_simple=true,
|
on_construct=function(pos)
|
||||||
drop="industrialtest:machine_block",
|
local meta=minetest.get_meta(pos)
|
||||||
on_construct=function(pos)
|
local inv=meta:get_inventory()
|
||||||
local meta=minetest.get_meta(pos)
|
inv:set_size("charged",1)
|
||||||
local inv=meta:get_inventory()
|
inv:set_size("fluid",1)
|
||||||
inv:set_size("charged",1)
|
inv:set_size("leftover",1)
|
||||||
inv:set_size("fluid",1)
|
meta:set_float("fluidAmount",0)
|
||||||
inv:set_size("leftover",1)
|
meta:set_string("fluid","")
|
||||||
meta:set_float("fluidAmount",0)
|
meta:set_string("formspec",getFormspec(0,0,""))
|
||||||
meta:set_string("fluid","")
|
industrialtest.api.addPowerStorage(meta,7000,industrialtest.api.lvPowerFlow,"oooooo")
|
||||||
meta:set_string("formspec",geothermalGeneratorFormspec(0,0,""))
|
end,
|
||||||
industrialtest.api.addPowerStorage(meta,7000,industrialtest.api.lvPowerFlow,"oooooo")
|
on_timer=function(pos,elapsed)
|
||||||
end,
|
local meta=minetest.get_meta(pos)
|
||||||
on_timer=function(pos,elapsed)
|
local inv=meta:get_inventory()
|
||||||
local meta=minetest.get_meta(pos)
|
local fluidSlot=inv:get_stack("fluid",1)
|
||||||
local inv=meta:get_inventory()
|
local chargedSlot=inv:get_stack("charged",1)
|
||||||
local fluidSlot=inv:get_stack("fluid",1)
|
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
|
||||||
local chargedSlot=inv:get_stack("charged",1)
|
local shouldUpdateFormspec=false
|
||||||
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
|
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
|
||||||
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
|
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
|
||||||
for _,item in ipairs(fuel.storageItems) do
|
for _,item in ipairs(fuel.storageItems) do
|
||||||
if item.name==fluidSlot:get_name() and item.leftover then
|
if item.name==fluidSlot:get_name() and item.leftover then
|
||||||
if inv:room_for_item("leftover",ItemStack(item.leftover)) then
|
if inv:room_for_item("leftover",ItemStack(item.leftover)) then
|
||||||
inv:add_item("leftover",ItemStack(item.leftover))
|
inv:add_item("leftover",ItemStack(item.leftover))
|
||||||
leftoverAddingSucceeded=true
|
leftoverAddingSucceeded=true
|
||||||
|
end
|
||||||
|
leftover=true
|
||||||
end
|
end
|
||||||
leftover=true
|
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
|
end
|
||||||
if not leftover or leftoverAddingSucceeded then
|
end
|
||||||
fluidSlot:take_item()
|
if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then
|
||||||
inv:set_stack("fluid",1,fluidSlot)
|
meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed)
|
||||||
meta:set_string("fluid",fuel.name)
|
local toAdd=math.ceil(config.getFuel(meta:get_string("fluid")).calorificValue*elapsed)
|
||||||
meta:set_float("fluidAmount",meta:get_float("fluidAmount")+1000)
|
industrialtest.api.addPower(meta,toAdd)
|
||||||
|
shouldUpdateFormspec=true
|
||||||
|
if config.registerActiveVariant then
|
||||||
|
minetest.swap_node(pos,{
|
||||||
|
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
|
||||||
|
inv:set_stack("charged",1,chargedSlot)
|
||||||
shouldUpdateFormspec=true
|
shouldUpdateFormspec=true
|
||||||
shouldRerunTimer=false
|
shouldRerunTimer=true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if flowTransferred then
|
||||||
|
shouldUpdateFormspec=true
|
||||||
|
end
|
||||||
|
|
||||||
|
if shouldUpdateFormspec then
|
||||||
|
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
|
||||||
|
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",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
|
||||||
|
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:"..config.name,definition)
|
||||||
|
if config.registerActiveVariant then
|
||||||
|
definition=table.copy(definition)
|
||||||
|
definition.description=nil
|
||||||
|
definition.tiles={
|
||||||
|
"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)
|
||||||
|
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=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
|
||||||
|
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:"..config.name,
|
||||||
|
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 flowTransferred then
|
||||||
|
shouldUpdateFormspec=true
|
||||||
|
end
|
||||||
|
|
||||||
|
if shouldUpdateFormspec then
|
||||||
|
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
|
||||||
|
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:"..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
|
end
|
||||||
end
|
end
|
||||||
if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then
|
if industrialtest.api.addPower(meta,powerToAdd)>0 then
|
||||||
meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed)
|
local def=minetest.registered_nodes[node.name]
|
||||||
local toAdd=math.ceil(industrialtest.api.getGeothermalGeneratorFuel(meta:get_string("fluid")).calorificValue*elapsed)
|
def._industrialtest_updateFormspec(meta)
|
||||||
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
|
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
|
||||||
inv:set_stack("charged",1,chargedSlot)
|
inv:set_stack("charged",1,chargedSlot)
|
||||||
shouldUpdateFormspec=true
|
|
||||||
shouldRerunTimer=true
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
}
|
})
|
||||||
if industrialtest.mtgAvailable then
|
minetest.register_craft({
|
||||||
definition.groups={
|
type="shaped",
|
||||||
cracky=1,
|
output="industrialtest:water_mill",
|
||||||
level=2
|
recipe={
|
||||||
|
{"",industrialtest.elementKeys.stick,""},
|
||||||
|
{industrialtest.elementKeys.stick,"industrialtest:generator",industrialtest.elementKeys.stick},
|
||||||
|
{"",industrialtest.elementKeys.stick,""}
|
||||||
}
|
}
|
||||||
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
|
-- Item processing machines
|
||||||
local function registerSimpleElectricItemProcessor(config)
|
local function registerSimpleElectricItemProcessor(config)
|
||||||
|
|
|
@ -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 |
Loading…
Reference in New Issue