Search in sources :

Example 11 with IFluidHandler

use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.

the class SemiBlockRequester method amountRequested.

@Override
public int amountRequested(FluidStack stack) {
    int totalRequestingAmount = getTotalRequestedAmount(stack);
    if (totalRequestingAmount > 0) {
        TileEntity te = getTileEntity();
        if (te instanceof IFluidHandler) {
            int count = 0;
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                FluidTankInfo[] infos = ((IFluidHandler) te).getTankInfo(d);
                if (infos != null) {
                    for (FluidTankInfo info : infos) {
                        if (info.fluid != null && info.fluid.getFluid() == stack.getFluid()) {
                            count += info.fluid.amount;
                        }
                    }
                    if (count > 0)
                        break;
                }
            }
            count += getIncomingFluid(stack.getFluid());
            int requested = Math.max(0, Math.min(stack.amount, totalRequestingAmount - count));
            return requested;
        }
    }
    return 0;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 12 with IFluidHandler

use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.

the class ProgWidgetLiquidInventoryCondition method getEvaluator.

@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
    return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {

        @Override
        protected boolean evaluate(ChunkPosition pos) {
            TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
            int count = 0;
            if (te instanceof IFluidHandler) {
                List<FluidStack> visitedStacks = new ArrayList<FluidStack>();
                IFluidHandler inv = (IFluidHandler) te;
                for (int i = 0; i < 6; i++) {
                    if (((ISidedWidget) widget).getSides()[i]) {
                        FluidTankInfo[] info = inv.getTankInfo(ForgeDirection.getOrientation(i));
                        if (info != null) {
                            for (FluidTankInfo inf : info) {
                                if (inf.fluid != null && !visitedStacks.contains(visitedStacks) && ProgWidgetLiquidFilter.isLiquidValid(inf.fluid.getFluid(), widget, 1)) {
                                    visitedStacks.add(inf.fluid);
                                    count += inf.fluid.amount;
                                }
                            }
                        }
                    }
                }
            } else {
                Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.getWorld().getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
                if (fluid != null && ProgWidgetLiquidFilter.isLiquidValid(fluid, widget, 1) && FluidUtils.isSourceBlock(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
                    count += 1000;
                }
            }
            return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount();
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) FluidStack(net.minecraftforge.fluids.FluidStack) ChunkPosition(net.minecraft.world.ChunkPosition) Fluid(net.minecraftforge.fluids.Fluid) ArrayList(java.util.ArrayList) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 13 with IFluidHandler

use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.

the class AmadronOfferCustom method returnStock.

public void returnStock() {
    TileEntity provider = getProvidingTileEntity();
    TileEntity returning = getReturningTileEntity();
    invert();
    while (inStock > 0) {
        int stock = Math.min(inStock, 50);
        stock = ContainerAmadron.capShoppingAmount(this, stock, returning instanceof IInventory ? (IInventory) returning : null, provider instanceof IInventory ? (IInventory) provider : null, returning instanceof IFluidHandler ? (IFluidHandler) returning : null, provider instanceof IFluidHandler ? (IFluidHandler) provider : null, null);
        if (stock > 0) {
            inStock -= stock;
            if (getInput() instanceof ItemStack) {
                ItemStack deliveringItems = (ItemStack) getInput();
                int amount = deliveringItems.stackSize * stock;
                List<ItemStack> stacks = new ArrayList<ItemStack>();
                while (amount > 0) {
                    ItemStack stack = deliveringItems.copy();
                    stack.stackSize = Math.min(amount, stack.getMaxStackSize());
                    stacks.add(stack);
                    amount -= stack.stackSize;
                }
                PneumaticRegistry.getInstance().deliverItemsAmazonStyle(provider.getWorldObj(), provider.xCoord, provider.yCoord, provider.zCoord, stacks.toArray(new ItemStack[stacks.size()]));
            } else {
                FluidStack deliveringFluid = ((FluidStack) getInput()).copy();
                deliveringFluid.amount *= stock;
                PneumaticRegistry.getInstance().deliverFluidAmazonStyle(provider.getWorldObj(), provider.xCoord, provider.yCoord, provider.zCoord, deliveringFluid);
            }
        } else {
            break;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 14 with IFluidHandler

use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.

the class AmadronOfferCustom method payout.

public void payout() {
    TileEntity returning = getReturningTileEntity();
    TileEntity provider = getProvidingTileEntity();
    if (pendingPayments > 0) {
        int paying = Math.min(pendingPayments, 50);
        paying = ContainerAmadron.capShoppingAmount(this, paying, provider instanceof IInventory ? (IInventory) provider : null, returning instanceof IInventory ? (IInventory) returning : null, provider instanceof IFluidHandler ? (IFluidHandler) provider : null, returning instanceof IFluidHandler ? (IFluidHandler) returning : null, null);
        if (paying > 0) {
            pendingPayments -= paying;
            if (getInput() instanceof ItemStack) {
                ItemStack deliveringItems = (ItemStack) getInput();
                int amount = deliveringItems.stackSize * paying;
                List<ItemStack> stacks = new ArrayList<ItemStack>();
                while (amount > 0) {
                    ItemStack stack = deliveringItems.copy();
                    stack.stackSize = Math.min(amount, stack.getMaxStackSize());
                    stacks.add(stack);
                    amount -= stack.stackSize;
                }
                PneumaticRegistry.getInstance().deliverItemsAmazonStyle(returning.getWorldObj(), returning.xCoord, returning.yCoord, returning.zCoord, stacks.toArray(new ItemStack[stacks.size()]));
            } else {
                FluidStack deliveringFluid = ((FluidStack) getInput()).copy();
                deliveringFluid.amount *= paying;
                PneumaticRegistry.getInstance().deliverFluidAmazonStyle(returning.getWorldObj(), returning.xCoord, returning.yCoord, returning.zCoord, deliveringFluid);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 15 with IFluidHandler

use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.

the class AmadronOfferManager method tryRestockCustomOffers.

public void tryRestockCustomOffers() {
    for (AmadronOffer offer : allOffers) {
        if (offer instanceof AmadronOfferCustom) {
            AmadronOfferCustom custom = (AmadronOfferCustom) offer;
            TileEntity input = custom.getProvidingTileEntity();
            TileEntity output = custom.getReturningTileEntity();
            int possiblePickups = ContainerAmadron.capShoppingAmount(custom.invert(), 50, input instanceof IInventory ? (IInventory) input : null, output instanceof IInventory ? (IInventory) output : null, input instanceof IFluidHandler ? (IFluidHandler) input : null, output instanceof IFluidHandler ? (IFluidHandler) output : null, null);
            if (possiblePickups > 0) {
                ChunkPosition pos = new ChunkPosition(input.xCoord, input.yCoord, input.zCoord);
                EntityDrone drone = ContainerAmadron.retrieveOrderItems(custom, possiblePickups, input.getWorldObj(), pos, input.getWorldObj(), pos);
                if (drone != null) {
                    drone.setHandlingOffer(custom.copy(), possiblePickups, null, "Restock");
                }
            }
            custom.invert();
            custom.payout();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ChunkPosition(net.minecraft.world.ChunkPosition) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Aggregations

IFluidHandler (net.minecraftforge.fluids.IFluidHandler)33 FluidStack (net.minecraftforge.fluids.FluidStack)26 TileEntity (net.minecraft.tileentity.TileEntity)24 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)19 ItemStack (net.minecraft.item.ItemStack)12 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)11 IInventory (net.minecraft.inventory.IInventory)8 FluidIdentifier (logisticspipes.utils.FluidIdentifier)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ISpecialTankAccessHandler (logisticspipes.interfaces.ISpecialTankAccessHandler)4 ISpecialTankHandler (logisticspipes.interfaces.ISpecialTankHandler)4 PipeFluidTransportLogistics (logisticspipes.transport.PipeFluidTransportLogistics)4 Item (net.minecraft.item.Item)4 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)3 Textures (logisticspipes.textures.Textures)3 TextureType (logisticspipes.textures.Textures.TextureType)3 Pair (logisticspipes.utils.tuples.Pair)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ChunkPosition (net.minecraft.world.ChunkPosition)3