Search in sources :

Example 1 with ISpecificRequester

use of pneumaticCraft.common.semiblock.ISpecificRequester in project PneumaticCraft by MineMaarten.

the class LogisticsManager method getRequestedAmount.

public static int getRequestedAmount(SemiBlockLogistics requester, ItemStack providingStack) {
    TileEntity te = requester.getTileEntity();
    if (!(te instanceof IInventory))
        return 0;
    int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester) requester).amountRequested(providingStack) : providingStack.stackSize;
    if (requestedAmount == 0)
        return 0;
    providingStack = providingStack.copy();
    providingStack.stackSize = requestedAmount;
    ItemStack remainder = providingStack.copy();
    remainder.stackSize += requester.getIncomingItems(providingStack);
    for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
        remainder = IOHelper.insert(te, remainder, d, true);
        if (remainder == null)
            break;
    }
    if (remainder != null)
        providingStack.stackSize -= remainder.stackSize;
    if (providingStack.stackSize <= 0)
        return 0;
    return providingStack.stackSize;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISpecificRequester(pneumaticCraft.common.semiblock.ISpecificRequester) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ISpecificRequester

use of pneumaticCraft.common.semiblock.ISpecificRequester in project PneumaticCraft by MineMaarten.

the class LogisticsManager method getRequestedAmount.

public static int getRequestedAmount(SemiBlockLogistics requester, FluidStack providingStack) {
    int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester) requester).amountRequested(providingStack) : providingStack.amount;
    if (requestedAmount == 0)
        return 0;
    providingStack = providingStack.copy();
    providingStack.amount = requestedAmount;
    FluidStack remainder = providingStack.copy();
    remainder.amount += requester.getIncomingFluid(remainder.getFluid());
    TileEntity te = requester.getTileEntity();
    if (te instanceof IFluidHandler) {
        IFluidHandler fluidHandler = (IFluidHandler) te;
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            int fluidFilled = fluidHandler.fill(d, remainder, false);
            if (fluidFilled > 0) {
                remainder.amount -= fluidFilled;
                break;
            }
        }
    }
    providingStack.amount -= remainder.amount;
    if (providingStack.amount <= 0)
        return 0;
    return providingStack.amount;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISpecificRequester(pneumaticCraft.common.semiblock.ISpecificRequester) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 ISpecificRequester (pneumaticCraft.common.semiblock.ISpecificRequester)2 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1