Search in sources :

Example 16 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.

the class GTUtility method fluidHandlerToList.

/**
 * @return a list of fluidstack linked with given fluid handler
 * modifications in list will reflect on fluid handler and wise-versa
 */
public static List<FluidStack> fluidHandlerToList(IMultipleTankHandler fluidInputs) {
    List<IFluidTank> backedList = fluidInputs.getFluidTanks();
    return new AbstractList<FluidStack>() {

        @Override
        public FluidStack set(int index, FluidStack element) {
            IFluidTank fluidTank = backedList.get(index);
            FluidStack oldStack = fluidTank.getFluid();
            if (!(fluidTank instanceof FluidTank))
                return oldStack;
            ((FluidTank) backedList.get(index)).setFluid(element);
            return oldStack;
        }

        @Override
        public FluidStack get(int index) {
            return backedList.get(index).getFluid();
        }

        @Override
        public int size() {
            return backedList.size();
        }
    };
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 17 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GTplusplus by GTNewHorizons.

the class GregtechPump method drainIFluidTank.

/*
	 * Vanilla IFluidTank
	 */
public boolean drainIFluidTank(TileEntity tTileEntity, ItemStack aStack, World aWorld, EntityPlayer aPlayer, int aX, int aY, int aZ) {
    if (tTileEntity == null) {
        Logger.INFO("Invalid Tile, somehow.");
        return false;
    }
    if ((tTileEntity instanceof IFluidTank || tTileEntity instanceof IFluidHandler)) {
        if (this.getFluid(aStack) == null || (this.getFluid(aStack) != null && this.getFluid(aStack).amount < this.getCapacity(aStack))) {
            Logger.INFO("Trying to find Stored Fluid - Behaviour Class.");
            FluidStack aStored = getStoredFluidOfVanillaTank(tTileEntity);
            if (aStored != null) {
                int mAmountInserted = fill(aStack, aStored);
                FluidStack newStackRemainingInTank;
                if (mAmountInserted > 0) {
                    if (mAmountInserted == aStored.amount) {
                        newStackRemainingInTank = null;
                    } else {
                        newStackRemainingInTank = FluidUtils.getFluidStack(aStored, (aStored.amount - mAmountInserted));
                    }
                    boolean b = setStoredFluidOfVanillaTank(tTileEntity, newStackRemainingInTank);
                    Logger.INFO("Cleared Tank? " + b + " | mAmountInserted: " + mAmountInserted);
                    Logger.INFO("Returning " + b + " - drainTankVanilla.");
                    if (b) {
                        PlayerUtils.messagePlayer(aPlayer, "Drained " + mAmountInserted + "L of " + aStored.getLocalizedName() + ".");
                    }
                    return b;
                }
            } else {
                Logger.INFO("Found no valid Fluidstack - drainTankVanilla.");
            }
        } else {
            Logger.INFO("Pump is full.");
        }
    }
    Logger.INFO("Could not drain vanilla tank.");
    return false;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 18 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GTplusplus by GTNewHorizons.

the class GregtechPump method tryDrainTile.

/**
 * Tile Handling
 */
/*
	 * Custom Fluid Handling for Tiles and GT Tiles.
	 */
public boolean tryDrainTile(ItemStack aStack, World aWorld, EntityPlayer aPlayer, int aX, int aY, int aZ) {
    try {
        if (aWorld.isRemote || aStack == null) {
            return false;
        } else {
            int aTier = (aStack.getItemDamage() - 1000);
            int removal;
            if (aTier == 0) {
                removal = 0;
            } else if (aTier == 1) {
                removal = 32;
            } else if (aTier == 2) {
                removal = 128;
            } else if (aTier == 3) {
                removal = 512;
            } else {
                removal = 8;
            }
            if (!canUse(aStack, removal) && aTier > 0) {
                PlayerUtils.messagePlayer(aPlayer, "Not enough power.");
                Logger.INFO("No Power");
                return false;
            }
            final Block aBlock = aWorld.getBlock(aX, aY, aZ);
            if (aBlock == null) {
                return false;
            }
            TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
            if (tTileEntity == null) {
                return false;
            } else {
                double aCharge = this.getCharge(aStack);
                boolean didDrain = false;
                if (aTier > 0 && aCharge > 0) {
                    if (discharge(aStack, removal, aTier, true, true, false) > 0) {
                        didDrain = true;
                    }
                } else if (aTier == 0) {
                    didDrain = true;
                } else {
                    didDrain = false;
                }
                if (didDrain) {
                    if ((tTileEntity instanceof IGregTechTileEntity)) {
                        return this.drainTankGT(tTileEntity, aStack, aWorld, aPlayer, aX, aY, aZ);
                    } else // Try support Standard Fluid Tanks too (May disable if dupes appear again)
                    if ((tTileEntity instanceof IFluidTank || tTileEntity instanceof IFluidHandler)) {
                        // return this.drainIFluidTank(tTileEntity, aStack, aWorld, aPlayer, aX, aY, aZ);
                        return false;
                    }
                }
            }
        }
    } catch (Throwable t) {
    }
    return false;
}
Also used : IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) Block(net.minecraft.block.Block) IFluidTank(net.minecraftforge.fluids.IFluidTank) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 19 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GTplusplus by GTNewHorizons.

the class GregtechPump method getStoredFluidOfVanillaTank.

public FluidStack getStoredFluidOfVanillaTank(IFluidHandler aTileEntity) {
    if (aTileEntity instanceof IFluidTank) {
        return getStoredFluidOfVanillaTank((IFluidTank) aTileEntity);
    }
    FluidStack f;
    AutoMap<FluidTankInfo[]> m = new AutoMap<FluidTankInfo[]>();
    for (int i = 0; i < 6; i++) {
        m.put(aTileEntity.getTankInfo(ForgeDirection.getOrientation(i)));
    }
    if (m.get(0) != null && m.get(0)[0] != null && m.get(0)[0].fluid != null) {
        return m.get(0)[0].fluid;
    } else {
        return null;
    }
}
Also used : FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) AutoMap(gtPlusPlus.api.objects.data.AutoMap)

Example 20 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project Binnie by ForestryMC.

the class MachineUtil method liquidInTank.

public boolean liquidInTank(final int tankIndex, final int amount) {
    IFluidTank tank = this.getTank(tankIndex);
    FluidStack drain = tank.drain(amount, false);
    return drain != null && drain.amount == amount;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Aggregations

IFluidTank (net.minecraftforge.fluids.IFluidTank)58 FluidStack (net.minecraftforge.fluids.FluidStack)30 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)10 FluidTank (net.minecraftforge.fluids.FluidTank)9 Nullable (javax.annotation.Nullable)6 Block (net.minecraft.block.Block)6 ItemStack (net.minecraft.item.ItemStack)6 TileEntity (net.minecraft.tileentity.TileEntity)5 NBTBase (net.minecraft.nbt.NBTBase)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 INBTSerializable (net.minecraftforge.common.util.INBTSerializable)4 Recipe (gregtech.api.recipes.Recipe)3 ArrayList (java.util.ArrayList)3 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)3 FluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity)2 FluidTankGT (gregapi.fluid.FluidTankGT)2 OreDictItemData (gregapi.oredict.OreDictItemData)2 FuelRecipe (gregtech.api.recipes.recipes.FuelRecipe)2 BlockLiquid (net.minecraft.block.BlockLiquid)2