Search in sources :

Example 6 with IFluidHandler

use of net.minecraftforge.fluids.IFluidHandler in project SimplyJetpacks by Tonius.

the class ItemJetpackFueller method onUsingTick.

@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos == null || blockPos.sideHit < 0) {
        player.setItemInUse(null, 1);
    } else {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
        if (player.worldObj.isRemote) {
            return;
        }
        ItemStack chestplate = player.getCurrentArmor(2);
        if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
            return;
        }
        ItemPack packItem = (ItemPack) chestplate.getItem();
        PackBase pack = packItem.getPack(chestplate);
        if (pack == null) {
            return;
        }
        FuelType fuelType = pack.fuelType;
        ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
        player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
        int pulled = 0;
        if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
            IEnergyProvider energyTile = (IEnergyProvider) tile;
            pulled = energyTile.extractEnergy(pullSide, toPull, false);
        } else if (fuelType == FuelType.FLUID) {
            if (tile instanceof IFluidHandler) {
                IFluidHandler fluidTile = (IFluidHandler) tile;
                FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
                if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
                    return;
                }
                fluid = fluidTile.drain(pullSide, toPull, true);
                pulled = fluid.amount;
            }
        }
        if (pulled > 0) {
            packItem.addFuel(chestplate, pulled, false);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) IEnergyProvider(cofh.api.energy.IEnergyProvider) FluidStack(net.minecraftforge.fluids.FluidStack) PackBase(tonius.simplyjetpacks.item.meta.PackBase) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) FuelType(tonius.simplyjetpacks.setup.FuelType) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 7 with IFluidHandler

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

the class LogisticsManager method tryProvide.

//curAI = new DroneAILiquidImport(drone, new FakeWidgetLogistics(provider.getPos(), providingStack));
// transportingFluid = new FluidStackWrapper(providingStack);
private void tryProvide(SemiBlockLogistics provider, SemiBlockLogistics requester, PriorityQueue<LogisticsTask> tasks) {
    IInventory providingInventory = IOHelper.getInventoryForTE(provider.getTileEntity());
    if (providingInventory != null) {
        if (requester instanceof IProvidingInventoryListener)
            ((IProvidingInventoryListener) requester).notify(provider.getTileEntity());
        for (int i = 0; i < providingInventory.getSizeInventory(); i++) {
            ItemStack providingStack = providingInventory.getStackInSlot(i);
            if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && IOHelper.canExtractItemFromInventory(providingInventory, providingStack, i, 0)) {
                int requestedAmount = getRequestedAmount(requester, providingStack);
                if (requestedAmount > 0) {
                    ItemStack stack = providingStack.copy();
                    stack.stackSize = requestedAmount;
                    tasks.add(new LogisticsTask(provider, requester, stack));
                }
            }
        }
    }
    if (provider.getTileEntity() instanceof IFluidHandler) {
        IFluidHandler providingTank = (IFluidHandler) provider.getTileEntity();
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            FluidStack providingStack = providingTank.drain(d, 16000, false);
            if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && providingTank.canDrain(d, providingStack.getFluid())) {
                int requestedAmount = getRequestedAmount(requester, providingStack);
                if (requestedAmount > 0) {
                    FluidStack stack = providingStack.copy();
                    stack.amount = requestedAmount;
                    tasks.add(new LogisticsTask(provider, requester, new FluidStackWrapper(stack)));
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISpecificProvider(pneumaticCraft.common.semiblock.ISpecificProvider) IProvidingInventoryListener(pneumaticCraft.common.semiblock.IProvidingInventoryListener) FluidStackWrapper(pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 8 with IFluidHandler

use of net.minecraftforge.fluids.IFluidHandler 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)

Example 9 with IFluidHandler

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

the class DroneAILiquidImport method emptyTank.

private boolean emptyTank(ChunkPosition pos, boolean simulate) {
    if (drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) {
        drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank");
        abort();
        return false;
    } else {
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        if (te instanceof IFluidHandler) {
            IFluidHandler tank = (IFluidHandler) te;
            for (int i = 0; i < 6; i++) {
                if (((ISidedWidget) widget).getSides()[i]) {
                    FluidStack importedFluid = tank.drain(ForgeDirection.getOrientation(i), Integer.MAX_VALUE, false);
                    if (importedFluid != null && ((ILiquidFiltered) widget).isFluidValid(importedFluid.getFluid())) {
                        int filledAmount = drone.getTank().fill(importedFluid, false);
                        if (filledAmount > 0) {
                            if (((ICountWidget) widget).useCount())
                                filledAmount = Math.min(filledAmount, getRemainingCount());
                            if (!simulate) {
                                decreaseCount(drone.getTank().fill(tank.drain(ForgeDirection.getOrientation(i), filledAmount, true), true));
                            }
                            return true;
                        }
                    }
                }
            }
            drone.addDebugEntry("gui.progWidget.liquidImport.debug.emptiedToMax", pos);
        } else if (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.getWorld().getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
            if (fluid != null && ((ILiquidFiltered) widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
                if (!simulate) {
                    decreaseCount(1000);
                    drone.getTank().fill(new FluidStack(fluid, 1000), true);
                    drone.getWorld().setBlockToAir(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
                }
                return true;
            }
        }
        return false;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILiquidFiltered(pneumaticCraft.common.progwidgets.ILiquidFiltered) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ICountWidget(pneumaticCraft.common.progwidgets.ICountWidget) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 10 with IFluidHandler

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

the class ItemAmadronTablet method getLiquidProvider.

public static IFluidHandler getLiquidProvider(ItemStack tablet) {
    ChunkPosition pos = getLiquidProvidingLocation(tablet);
    if (pos != null) {
        int dimension = getLiquidProvidingDimension(tablet);
        TileEntity te = PneumaticCraftUtils.getTileEntity(pos, dimension);
        if (te instanceof IFluidHandler)
            return (IFluidHandler) te;
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) 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