diff --git a/machines/compressor.lua b/machines/compressor.lua index 3cbbb64..6282ec9 100644 --- a/machines/compressor.lua +++ b/machines/compressor.lua @@ -62,8 +62,38 @@ function industrialtest.Compressor.getCraftResult(self,itemstack) } 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.api.registerPumpTarget("industrialtest:compressor","o") +industrialtest.api.registerPumpTarget("industrialtest:compressor_active","o") + minetest.register_craft({ type="shaped", output="industrialtest:compressor", diff --git a/machines/miner.lua b/machines/miner.lua index 34442f6..7603118 100644 --- a/machines/miner.lua +++ b/machines/miner.lua @@ -166,6 +166,8 @@ function industrialtest.Miner.onConstruct(self,pos) inv:set_size("powerStorage",1) inv:set_size("upgrades",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) end @@ -283,6 +285,14 @@ function industrialtest.Miner.update(self,pos,elapsed,meta,inv) srcSlot:take_item(1) inv:set_stack("src",1,srcSlot) 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) self.placeMiningPipe(pos,targetPos) inv:add_item("dst",drop) @@ -375,8 +385,27 @@ function industrialtest.Miner.placeMiningPipe(minerPos,pos) meta:set_string("miner",minetest.serialize(minerPos)) 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.api.registerPumpTarget("industrialtest:miner","i") + minetest.register_craft({ type="shaped", output="industrialtest:miner",