Search in sources :

Example 1 with ChunkPositionSorter

use of pneumaticCraft.common.ai.ChunkPositionSorter in project PneumaticCraft by MineMaarten.

the class TileEntityGasLift method suckLiquid.

public boolean suckLiquid() {
    Block block = worldObj.getBlock(xCoord, yCoord - currentDepth - 1, zCoord);
    Fluid fluid = FluidRegistry.lookupFluidForBlock(block);
    if (fluid != null) {
        if (fill(ForgeDirection.UNKNOWN, new FluidStack(fluid, 1000), false) == 1000) {
            if (pumpingLake == null) {
                pumpingLake = new ArrayList<ChunkPosition>();
                Stack<ChunkPosition> pendingPositions = new Stack<ChunkPosition>();
                ChunkPosition thisPos = new ChunkPosition(xCoord, yCoord - currentDepth - 1, zCoord);
                pendingPositions.add(thisPos);
                pumpingLake.add(thisPos);
                while (!pendingPositions.empty()) {
                    ChunkPosition checkingPos = pendingPositions.pop();
                    for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                        if (d == ForgeDirection.DOWN)
                            continue;
                        ChunkPosition newPos = new ChunkPosition(checkingPos.chunkPosX + d.offsetX, checkingPos.chunkPosY + d.offsetY, checkingPos.chunkPosZ + d.offsetZ);
                        if (PneumaticCraftUtils.distBetween(newPos, xCoord + 0.5, yCoord - currentDepth - 1, zCoord + 0.5) <= MAX_PUMP_RANGE && worldObj.getBlock(newPos.chunkPosX, newPos.chunkPosY, newPos.chunkPosZ) == block && !pumpingLake.contains(newPos)) {
                            pendingPositions.add(newPos);
                            pumpingLake.add(newPos);
                        }
                    }
                }
                Collections.sort(pumpingLake, new ChunkPositionSorter(xCoord + 0.5, yCoord - currentDepth - 1, zCoord + 0.5));
                Collections.reverse(pumpingLake);
            }
            ChunkPosition curPos = null;
            boolean foundSource = false;
            while (pumpingLake.size() > 0) {
                curPos = pumpingLake.get(0);
                if (worldObj.getBlock(curPos.chunkPosX, curPos.chunkPosY, curPos.chunkPosZ) == block && worldObj.getBlockMetadata(curPos.chunkPosX, curPos.chunkPosY, curPos.chunkPosZ) == 0) {
                    foundSource = true;
                    break;
                }
                pumpingLake.remove(0);
            }
            if (pumpingLake.size() == 0) {
                pumpingLake = null;
            } else if (foundSource) {
                worldObj.setBlockToAir(curPos.chunkPosX, curPos.chunkPosY, curPos.chunkPosZ);
                fill(ForgeDirection.UNKNOWN, new FluidStack(fluid, 1000), true);
                addAir(-100, ForgeDirection.UNKNOWN);
                status = 1;
            }
        }
        return true;
    } else {
        pumpingLake = null;
        return false;
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ChunkPosition(net.minecraft.world.ChunkPosition) ChunkPositionSorter(pneumaticCraft.common.ai.ChunkPositionSorter) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack) FluidStack(net.minecraftforge.fluids.FluidStack)

Aggregations

Stack (java.util.Stack)1 Block (net.minecraft.block.Block)1 ItemStack (net.minecraft.item.ItemStack)1 ChunkPosition (net.minecraft.world.ChunkPosition)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 Fluid (net.minecraftforge.fluids.Fluid)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 ChunkPositionSorter (pneumaticCraft.common.ai.ChunkPositionSorter)1