Java Code Examples for net.minecraftforge.fluids.IFluidTank#getFluid()

The following examples show how to use net.minecraftforge.fluids.IFluidTank#getFluid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkableTieredMetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected boolean canInputFluid(FluidStack inputFluid) {
    RecipeMap<?> recipeMap = workable.recipeMap;
    if (recipeMap.canInputFluidForce(inputFluid.getFluid()))
        return true; //if recipe map forces input of given fluid, return true
    Set<Recipe> matchingRecipes = null;
    for (IFluidTank fluidTank : importFluids) {
        FluidStack fluidInTank = fluidTank.getFluid();
        if (fluidInTank != null) {
            if (matchingRecipes == null) {
                //if we didn't have a list of recipes with any fluids, obtain it from first tank with fluid
                matchingRecipes = new HashSet<>(recipeMap.getRecipesForFluid(fluidInTank));
            } else {
                //else, remove recipes that don't contain fluid in this tank from list
                matchingRecipes.removeIf(recipe -> !recipe.hasInputFluid(fluidInTank));
            }
        }
    }
    if (matchingRecipes == null) {
        //if all tanks are empty, generally fluid can be inserted if there are recipes for it
        return !recipeMap.getRecipesForFluid(inputFluid).isEmpty();
    } else {
        //otherwise, we can insert fluid only if one of recipes accept it as input
        return matchingRecipes.stream().anyMatch(recipe -> recipe.hasInputFluid(inputFluid));
    }
}
 
Example 2
Source File: ItemHelper.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
public static void extractFluidsFromTanks(List<IFluidTank> tanks, List<FluidStack> fluids)
{
    LinkedList<IFluidTank> remaining = Lists.newLinkedList(tanks);

    for (FluidStack stack : fluids)
    {
        for (Iterator<IFluidTank> iterator = remaining.iterator(); iterator.hasNext(); )
        {
            IFluidTank tank = iterator.next();
            if (tank.getFluid() != null && tank.getFluid().getFluid().getName().equals(stack.getFluid().getName()))
            {
                FluidStack drained = tank.drain(stack.amount, false);
                if (drained != null && drained.amount == stack.amount)
                {
                    tank.drain(stack.amount, true);
                    iterator.remove();
                    break;
                }
            }
        }
    }
}
 
Example 3
Source File: TileEntityPoweredInventoryFluid.java    From BigReactors with MIT License 6 votes vote down vote up
/**
 * Returns true if the given fluid can be inserted into the given direction.
 * 
 * More formally, this should return true if fluid is able to enter from the given direction.
 */
public boolean canFill(ForgeDirection from, Fluid fluid) {
	int tankIdx = 0;
	if(from != ForgeDirection.UNKNOWN) {
		tankIdx = getExposedTankFromSide(from.ordinal());
	}

	if(tankIdx == FLUIDTANK_NONE) { return false; }

	IFluidTank tank = tanks[tankIdx];
	if(tank.getFluidAmount() <= 0) {
		return true;
	}
	else {
		return tank.getFluid().fluidID == fluid.getID();
	}
}
 
Example 4
Source File: TileEntityPoweredInventoryFluid.java    From BigReactors with MIT License 6 votes vote down vote up
/**
 * Returns true if the given fluid can be extracted from the given direction.
 * 
 * More formally, this should return true if fluid is able to leave from the given direction.
 */
public boolean canDrain(ForgeDirection from, Fluid fluid) {
	int tankIdx = 0;
	if(from != ForgeDirection.UNKNOWN) {
		tankIdx = getExposedTankFromSide(from.ordinal());
	}

	if(tankIdx == FLUIDTANK_NONE) { return false; }

	IFluidTank tank = tanks[tankIdx];
	if(tank.getFluidAmount() <= 0) {
		return false;
	}
	else {
		return tank.getFluid().fluidID == fluid.getID();
	}
}
 
Example 5
Source File: ContainerCS4.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void detectAndSendChanges()
{
    super.detectAndSendChanges();

    for (int i = 0; i < tanks.size(); i++)
    {
        IFluidTank tank = tanks.get(i);

        FluidStack prev = fluidStacks.get(i);
        FluidStack current = tank.getFluid();

        if (!ItemHelper.fluidStackEqual(prev, current))
        {
            PacketSyncContainerFluid packet = new PacketSyncContainerFluid(windowId, i, current);
            for (IContainerListener listener : listeners)
            {
                if (listener instanceof EntityPlayerMP)
                {
                    EntityPlayerMP player = (EntityPlayerMP) listener;
                    CustomStuff4.network.sendTo(packet, player);
                }
            }

            fluidStacks.set(i, current == null ? null : current.copy());
        }
    }
}
 
Example 6
Source File: TileEnderTank.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public int comparatorInput() {
    IFluidTank tank = getStorage();
    FluidStack fluid = tank.getFluid();
    if (fluid == null) {
        fluid = FluidStack.EMPTY;
    }
    return fluid.getAmount() * 14 / tank.getCapacity() + (fluid.getAmount() > 0 ? 1 : 0);
}