private long dispatchEnergyToNode(BlockPos nodePos, long voltage, long amperage) { long amperesUsed = 0L; //use pooled mutable to avoid creating new objects every tick World world = tileEntityCable.getPipeWorld(); PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); for(EnumFacing facing : EnumFacing.VALUES) { blockPos.setPos(nodePos).move(facing); //do not allow cables to load chunks if(!world.isBlockLoaded(nodePos)) continue; TileEntity tileEntity = world.getTileEntity(blockPos); if(tileEntity == null || tileEntityCable.getPipeBlock().getPipeTileEntity(tileEntity) != null) continue; IEnergyContainer energyContainer = tileEntity.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, null); if(energyContainer == null) continue; amperesUsed += energyContainer.acceptEnergyFromNetwork(facing.getOpposite(), voltage, amperage - amperesUsed); if(amperesUsed == amperage) break; } blockPos.release(); return amperesUsed; }
public void pullFluidsFromNearbyHandlers(EnumFacing... allowedFaces) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); for(EnumFacing nearbyFacing : allowedFaces) { blockPos.setPos(getPos()).move(nearbyFacing); IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), blockPos, nearbyFacing.getOpposite()); if(fluidHandler == null) continue; for(IFluidTankProperties tankProperties : fluidHandler.getTankProperties()) { FluidStack currentFluid = tankProperties.getContents(); if(currentFluid == null || currentFluid.amount == 0) continue; currentFluid.amount = Integer.MAX_VALUE; FluidStack fluidStack = fluidHandler.drain(currentFluid, false); if(fluidStack == null || fluidStack.amount == 0) continue; int canInsertAmount = importFluids.fill(fluidStack, false); if(canInsertAmount > 0) { fluidStack = fluidHandler.drain(canInsertAmount, true); importFluids.fill(fluidStack, true); } } } blockPos.release(); }
public void pushFluidsIntoNearbyHandlers(EnumFacing... allowedFaces) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); for(EnumFacing nearbyFacing : allowedFaces) { blockPos.setPos(getPos()).move(nearbyFacing); IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), blockPos, nearbyFacing.getOpposite()); if(fluidHandler == null) continue; for(int tankIndex = 0; tankIndex < exportFluids.getTanks(); tankIndex++) { IFluidTank tank = exportFluids.getTankAt(tankIndex); FluidStack fluidStack = tank.getFluid(); if(fluidStack != null && fluidHandler.fill(fluidStack, false) != 0) { int filledAmount = fluidHandler.fill(fluidStack, true); tank.drain(filledAmount, true); } } } blockPos.release(); }
public static void pushFluidsFromTank(IPipeTile<?, ?> pipeTile) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); for(EnumFacing side : EnumFacing.VALUES) { blockPos.setPos(pipeTile.getPipePos()).move(side); TileEntity tileEntity = pipeTile.getPipeWorld().getTileEntity(blockPos); IFluidHandler sourceHandler = pipeTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); IFluidHandler receiverHandler = tileEntity == null ? null : tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite()); if(sourceHandler == null || receiverHandler == null) { continue; } CoverPump.moveHandlerFluids(sourceHandler, receiverHandler, Integer.MAX_VALUE, FLUID_FILTER_ALWAYS_TRUE); } blockPos.release(); }
public void pullItemsFromNearbyHandlers(EnumFacing... allowedFaces) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); for(EnumFacing nearbyFacing : allowedFaces) { blockPos.setPos(getPos()).move(nearbyFacing); TileEntity tileEntity = getWorld().getTileEntity(blockPos); IItemHandler itemHandler = tileEntity == null ? null : tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing.getOpposite()); if(itemHandler == null) { continue; } moveInventoryItems(itemHandler, importItems); } blockPos.release(); }
public void pushItemsIntoNearbyHandlers(EnumFacing... allowedFaces) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); for(EnumFacing nearbyFacing : allowedFaces) { blockPos.setPos(getPos()).move(nearbyFacing); TileEntity tileEntity = getWorld().getTileEntity(blockPos); IItemHandler itemHandler = tileEntity == null ? null : tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing.getOpposite()); if(itemHandler == null) { continue; } moveInventoryItems(exportItems, itemHandler); } blockPos.release(); }
protected int doTransferFluids(int transferLimit) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); blockPos.setPos(coverHolder.getPos()).move(attachedSide); TileEntity tileEntity = coverHolder.getWorld().getTileEntity(blockPos); blockPos.release(); IFluidHandler fluidHandler = tileEntity == null ? null : tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, attachedSide.getOpposite()); IFluidHandler myFluidHandler = coverHolder.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, attachedSide); if(fluidHandler == null || myFluidHandler == null) { return 0; } return doTransferFluidsInternal(myFluidHandler, fluidHandler, transferLimit); }