Register Compressor and Miner as machines which can interact with Pump
This commit is contained in:
parent
8ca2a44070
commit
8f286ebcbc
@ -62,8 +62,38 @@ function industrialtest.Compressor.getCraftResult(self,itemstack)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function industrialtest.Compressor.canPushFluid(self,pos,fluidType,fluidAmount)
|
||||||
|
local meta=minetest.get_meta(pos)
|
||||||
|
local compressedFluid=industrialtest.api.getCompressedFluid(fluidType)
|
||||||
|
if not self.isRecipeOverride(meta) and compressedFluid and fluidAmount>=compressedFluid.requiredAmount then
|
||||||
|
local inv=meta:get_inventory()
|
||||||
|
local resultingStack=ItemStack(compressedFluid.result)
|
||||||
|
if inv:room_for_item("dst",resultingStack) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Called by Pump when Compressor is next to it while it tries to push fluid
|
||||||
|
function industrialtest.Compressor.onPumpFluidPush(self,pos,pumpPos,fluidType,fluidAmount)
|
||||||
|
local compressedFluid=industrialtest.api.getCompressedFluid(fluidType)
|
||||||
|
if compressedFluid then
|
||||||
|
local meta=minetest.get_meta(pos)
|
||||||
|
-- If recipe can be overriden keep information about this in meta so it's picked up by superclass
|
||||||
|
meta:set_string("recipeOverride",compressedFluid.result)
|
||||||
|
meta:set_int("recipeOverrideMaxTime",compressedFluid.time)
|
||||||
|
fluidAmount=fluidAmount-compressedFluid.requiredAmount
|
||||||
|
self:triggerIfNeeded(pos)
|
||||||
|
end
|
||||||
|
return fluidAmount
|
||||||
|
end
|
||||||
|
|
||||||
industrialtest.Compressor:register()
|
industrialtest.Compressor:register()
|
||||||
|
|
||||||
|
industrialtest.api.registerPumpTarget("industrialtest:compressor","o")
|
||||||
|
industrialtest.api.registerPumpTarget("industrialtest:compressor_active","o")
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:compressor",
|
output="industrialtest:compressor",
|
||||||
|
|||||||
@ -166,6 +166,8 @@ function industrialtest.Miner.onConstruct(self,pos)
|
|||||||
inv:set_size("powerStorage",1)
|
inv:set_size("powerStorage",1)
|
||||||
inv:set_size("upgrades",1)
|
inv:set_size("upgrades",1)
|
||||||
meta:set_int("level",pos.y-1)
|
meta:set_int("level",pos.y-1)
|
||||||
|
-- Keep last fluid node here so pump has more time to access it
|
||||||
|
meta:set_string("lastFluidNode","")
|
||||||
industrialtest.ElectricMachine.onConstruct(self,pos)
|
industrialtest.ElectricMachine.onConstruct(self,pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -283,6 +285,14 @@ function industrialtest.Miner.update(self,pos,elapsed,meta,inv)
|
|||||||
srcSlot:take_item(1)
|
srcSlot:take_item(1)
|
||||||
inv:set_stack("src",1,srcSlot)
|
inv:set_stack("src",1,srcSlot)
|
||||||
local targetPos=vector.new(pos.x,level,pos.z)
|
local targetPos=vector.new(pos.x,level,pos.z)
|
||||||
|
|
||||||
|
-- Check if target node is fluid so pump, if attached, can get it
|
||||||
|
local targetNode=minetest.get_node(targetPos)
|
||||||
|
local targetFluid=industrialtest.api.getPumpFluid(targetNode.name)
|
||||||
|
if targetFluid then
|
||||||
|
meta:set_string("lastFluidNode",targetNode.name)
|
||||||
|
end
|
||||||
|
|
||||||
local drop=self.getNodeDrop(targetPos)
|
local drop=self.getNodeDrop(targetPos)
|
||||||
self.placeMiningPipe(pos,targetPos)
|
self.placeMiningPipe(pos,targetPos)
|
||||||
inv:add_item("dst",drop)
|
inv:add_item("dst",drop)
|
||||||
@ -375,8 +385,27 @@ function industrialtest.Miner.placeMiningPipe(minerPos,pos)
|
|||||||
meta:set_string("miner",minetest.serialize(minerPos))
|
meta:set_string("miner",minetest.serialize(minerPos))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function industrialtest.Miner.pullFluid(self,pos,amount)
|
||||||
|
local meta=minetest.get_meta(pos)
|
||||||
|
local lastFluidNode=meta:get_string("lastFluidNode")
|
||||||
|
if lastFluidNode~="" then
|
||||||
|
local result={
|
||||||
|
fluidType=lastFluidNode
|
||||||
|
}
|
||||||
|
result.remaining=industrialtest.api.nodeFluidCapacity
|
||||||
|
-- If everything was pulled then change to empty
|
||||||
|
if amount>=industrialtest.api.nodeFluidCapacity then
|
||||||
|
meta:set_string("lastFluidNode","")
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
industrialtest.Miner:register()
|
industrialtest.Miner:register()
|
||||||
|
|
||||||
|
industrialtest.api.registerPumpTarget("industrialtest:miner","i")
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:miner",
|
output="industrialtest:miner",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user