Implement storage cells
This commit is contained in:
parent
4c0ea7cdb0
commit
b8aff72da2
58
api.lua
58
api.lua
|
@ -22,6 +22,7 @@ industrialtest.api.compressorRecipes={}
|
|||
industrialtest.api.extractorRecipes={}
|
||||
industrialtest.api.geothermalGeneratorFuels={}
|
||||
industrialtest.api.waterMillFuels={}
|
||||
industrialtest.api.storageCells={}
|
||||
|
||||
industrialtest.api.lvPowerFlow=600
|
||||
industrialtest.api.mvPowerFlow=2400
|
||||
|
@ -363,6 +364,63 @@ industrialtest.api.registerResourceDust=function(name,displayName,resources,colo
|
|||
end
|
||||
end
|
||||
end
|
||||
-- \brief Registers cell with certain fluid
|
||||
-- \param name Technical name of cell
|
||||
-- \param displayName Display name of cell
|
||||
-- \param node Node which can be picked up with this cell
|
||||
-- \returns nil
|
||||
industrialtest.api.registerStorageCell=function(name,displayName,node,modname)
|
||||
if not modname then
|
||||
modname="industrialtest"
|
||||
end
|
||||
minetest.register_craftitem("industrialtest:"..name.."_cell",{
|
||||
description=S(displayName.." Cell"),
|
||||
inventory_image=modname.."_"..name.."_cell.png",
|
||||
on_place=function(itemstack,user,pointed)
|
||||
if pointed.type~="node" or not user or not user:is_player() then
|
||||
return nil
|
||||
end
|
||||
local node=minetest.get_node_or_nil(pointed.above)
|
||||
local storage=industrialtest.api.getStorageCell("industrialtest:"..name.."_cell")
|
||||
if storage.node then
|
||||
if node.name~="air" and node.name~=storage.node then
|
||||
return nil
|
||||
end
|
||||
minetest.set_node(pointed.above,{name=storage.node})
|
||||
if itemstack:get_count()==1 then
|
||||
itemstack:set_name("industrialtest:empty_cell")
|
||||
else
|
||||
local inv=user:get_inventory()
|
||||
inv:add_item("main",ItemStack("industrialtest:empty_cell"))
|
||||
itemstack:take_item()
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
return nil
|
||||
end
|
||||
})
|
||||
industrialtest.api.storageCells["industrialtest:"..name.."_cell"]={
|
||||
name="industrialtest:"..name.."_cell",
|
||||
node=node
|
||||
}
|
||||
end
|
||||
-- \brief Returns registred storage cell by name
|
||||
-- \param name Storage cell name
|
||||
-- \returns Table with following keys: name, node or nil in case of failure
|
||||
industrialtest.api.getStorageCell=function(name)
|
||||
return industrialtest.api.storageCells[name]
|
||||
end
|
||||
-- \brief Returns registered storage cells by node
|
||||
-- \param node Node ID
|
||||
-- \returns Table with following keys: name, node or nil in case of failure
|
||||
industrialtest.api.getStorageCellByNode=function(node)
|
||||
for _,value in pairs(industrialtest.api.storageCells) do
|
||||
if value.node==node then
|
||||
return value
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
-- \brief Registers macerator recipe
|
||||
-- \param config Table with keys: <output>, <recipe>, [time(2)]
|
||||
-- \returns nil
|
||||
|
|
|
@ -320,6 +320,79 @@ minetest.register_craft({
|
|||
recipe="industrialtest:bronze_dust"
|
||||
})
|
||||
|
||||
-- Cells
|
||||
minetest.register_craftitem("industrialtest:empty_cell",{
|
||||
description=S("Empty Cell"),
|
||||
inventory_image="industrialtest_empty_cell.png",
|
||||
liquids_pointable=true,
|
||||
on_place=function(itemstack,user,pointed)
|
||||
if pointed.type~="node" or not user or not user:is_player() then
|
||||
return nil
|
||||
end
|
||||
local node=minetest.get_node_or_nil(pointed.under)
|
||||
if not node then
|
||||
return nil
|
||||
end
|
||||
local storage=industrialtest.api.getStorageCellByNode(node.name)
|
||||
if not storage then
|
||||
return nil
|
||||
end
|
||||
if itemstack:get_count()==1 then
|
||||
itemstack:set_name(storage.name)
|
||||
else
|
||||
local inv=user:get_inventory()
|
||||
inv:add_item("main",ItemStack(storage.name))
|
||||
itemstack:take_item()
|
||||
end
|
||||
minetest.remove_node(pointed.under)
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:empty_cell 16",
|
||||
recipe={
|
||||
{"",industrialtest.elementKeys.tinIngot,""},
|
||||
{industrialtest.elementKeys.tinIngot,"",industrialtest.elementKeys.tinIngot},
|
||||
{"",industrialtest.elementKeys.tinIngot,""}
|
||||
}
|
||||
})
|
||||
industrialtest.api.registerStorageCell("water","Water",industrialtest.elementKeys.waterSource)
|
||||
if industrialtest.mtgAvailable then
|
||||
industrialtest.api.registerStorageCell("river_water","River Water","default:river_water_source")
|
||||
end
|
||||
industrialtest.api.registerStorageCell("lava","Lava",industrialtest.elementKeys.lavaSource)
|
||||
industrialtest.api.registerStorageCell("uranium","Uranium")
|
||||
minetest.register_craft({
|
||||
type="shapeless",
|
||||
output="industrialtest:uranium_cell",
|
||||
recipe={
|
||||
"industrialtest:empty_cell",
|
||||
"industrialtest:uranium_ingot"
|
||||
}
|
||||
})
|
||||
industrialtest.api.registerStorageCell("coolant","Coolant")
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:coolant_cell 16",
|
||||
recipe={
|
||||
{"",industrialtest.elementKeys.tinIngot,""},
|
||||
{industrialtest.elementKeys.tinIngot,"industrialtest:water_cell",industrialtest.elementKeys.tinIngot},
|
||||
{"",industrialtest.elementKeys.tinIngot,""}
|
||||
}
|
||||
})
|
||||
if industrialtest.mtgAvailable then
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:coolant_cell 16",
|
||||
recipe={
|
||||
{"",industrialtest.elementKeys.tinIngot,""},
|
||||
{industrialtest.elementKeys.tinIngot,"industrialtest:river_water_cell",industrialtest.elementKeys.tinIngot},
|
||||
{"",industrialtest.elementKeys.tinIngot,""}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
-- Other items
|
||||
minetest.register_craftitem("industrialtest:electronic_circuit",{
|
||||
description=S("Electronic Circuit"),
|
||||
|
|
12
crafts.lua
12
crafts.lua
|
@ -84,6 +84,10 @@ industrialtest.api.registerGeothermalGeneratorFuel({
|
|||
{
|
||||
name=industrialtest.elementKeys.bucketWithLava,
|
||||
leftover=industrialtest.elementKeys.bucket
|
||||
},
|
||||
{
|
||||
name="industrialtest:lava_cell",
|
||||
leftover="industrialtest:empty_cell"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -97,6 +101,10 @@ industrialtest.api.registerWaterMillFuel({
|
|||
{
|
||||
name=industrialtest.elementKeys.bucketWithWater,
|
||||
leftover=industrialtest.elementKeys.bucket
|
||||
},
|
||||
{
|
||||
name="industrialtest:water_cell",
|
||||
leftover="industrialtest:empty_cell"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -109,6 +117,10 @@ if industrialtest.mtgAvailable then
|
|||
{
|
||||
name="bucket:bucket_river_water",
|
||||
leftover=industrialtest.elementKeys.bucket
|
||||
},
|
||||
{
|
||||
name="industrialtest:river_water_cell",
|
||||
leftover="industrialtest:empty_cell"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue