Search in sources :

Example 1 with ITankContainer

use of net.minecraftforge.liquids.ITankContainer in project MineFactoryReloaded by powercrystals.

the class TileEntityLiquidRouter method weightedRouteLiquid.

private int weightedRouteLiquid(LiquidStack resource, int[] routes, int amountRemaining, boolean doFill) {
    if (amountRemaining >= totalWeight(routes)) {
        int startingAmount = amountRemaining;
        for (int i = 0; i < routes.length; i++) {
            TileEntity te = BlockPosition.getAdjacentTileEntity(this, _outputDirections[i]);
            int amountForThisRoute = startingAmount * routes[i] / totalWeight(routes);
            if (te instanceof ITankContainer && amountForThisRoute > 0) {
                amountRemaining -= ((ITankContainer) te).fill(_outputDirections[i].getOpposite(), new LiquidStack(resource.itemID, amountForThisRoute, resource.itemMeta), doFill);
                if (amountRemaining <= 0) {
                    break;
                }
            }
        }
    }
    if (0 < amountRemaining && amountRemaining < totalWeight(routes)) {
        int outdir = weightedRandomSide(routes);
        TileEntity te = BlockPosition.getAdjacentTileEntity(this, _outputDirections[outdir]);
        if (te instanceof ITankContainer) {
            amountRemaining -= ((ITankContainer) te).fill(_outputDirections[outdir].getOpposite(), new LiquidStack(resource.itemID, amountRemaining, resource.itemMeta), doFill);
        }
    }
    return amountRemaining;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LiquidStack(net.minecraftforge.liquids.LiquidStack) ITankContainer(net.minecraftforge.liquids.ITankContainer)

Example 2 with ITankContainer

use of net.minecraftforge.liquids.ITankContainer in project MineFactoryReloaded by powercrystals.

the class MFRLiquidMover method pumpLiquid.

public static void pumpLiquid(ILiquidTank tank, TileEntityFactory from) {
    if (tank != null && tank.getLiquid() != null && tank.getLiquid().amount > 0) {
        LiquidStack l = tank.getLiquid().copy();
        l.amount = Math.min(l.amount, LiquidContainerRegistry.BUCKET_VOLUME);
        for (BlockPosition adj : new BlockPosition(from).getAdjacent(true)) {
            TileEntity tile = from.worldObj.getBlockTileEntity(adj.x, adj.y, adj.z);
            if (tile instanceof ITankContainer) {
                int filled = ((ITankContainer) tile).fill(adj.orientation.getOpposite(), l, true);
                tank.drain(filled, true);
                l.amount -= filled;
                if (l.amount <= 0) {
                    break;
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LiquidStack(net.minecraftforge.liquids.LiquidStack) BlockPosition(powercrystals.core.position.BlockPosition) ITankContainer(net.minecraftforge.liquids.ITankContainer)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)2 ITankContainer (net.minecraftforge.liquids.ITankContainer)2 LiquidStack (net.minecraftforge.liquids.LiquidStack)2 BlockPosition (powercrystals.core.position.BlockPosition)1