net.minecraftforge.fluids.IFluidTank Java Examples

The following examples show how to use net.minecraftforge.fluids.IFluidTank. 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: 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 #2
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 #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
/**
 * Return the tank that this tank container desired to be used for the specified fluid type from the specified direction
 *
 * @param direction the direction
 * @param type the fluid type, null is always an acceptable value
 * @return a tank or null for no such tank
 */
public IFluidTank getTank(ForgeDirection direction, FluidStack type) {
	if(direction == ForgeDirection.UNKNOWN) {
		return null;
	}
	else {
		int tankIdx = getExposedTankFromSide(direction.ordinal());
		if(tankIdx == FLUIDTANK_NONE) {
			return null;
		}
		
		IFluidTank t = tanks[tankIdx];
		if(type == null || isFluidValidForTank(tankIdx, type)) {
			return t;
		}
		
		return null;
	}
}
 
Example #5
Source File: TileEntitySimple.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public IFluidTank getFluidTank(String name)
{
    String moduleName;
    String sourceName;
    TileEntityModule module;

    if (name.contains(":"))
    {
        String[] split = name.split(":");
        moduleName = split[0];
        sourceName = split[1];
    } else
    {
        moduleName = name;
        sourceName = name;
    }

    module = modules.get(moduleName);
    if (module instanceof FluidSource)
        return ((FluidSource) module).getFluidTank(sourceName);

    return null;
}
 
Example #6
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 #7
Source File: MetaTileEntityFluidHatch.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ModularUI.Builder createTankUI(IFluidTank fluidTank, IItemHandlerModifiable containerInventory, String title, EntityPlayer entityPlayer) {
    Builder builder = ModularUI.defaultBuilder();
    builder.image(7, 16, 81, 55, GuiTextures.DISPLAY);
    TankWidget tankWidget = new TankWidget(fluidTank, 69, 52, 18, 18)
        .setHideTooltip(true).setAlwaysShowFull(true);
    builder.widget(tankWidget);
    builder.label(11, 20, "gregtech.gui.fluid_amount", 0xFFFFFF);
    builder.dynamicLabel(11, 30, tankWidget::getFormattedFluidAmount, 0xFFFFFF);
    builder.dynamicLabel(11, 40, tankWidget::getFluidLocalizedName, 0xFFFFFF);
    return builder.label(6, 6, title)
        .widget(new FluidContainerSlotWidget(containerInventory, 0, 90, 17, !isExportHatch)
            .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.IN_SLOT_OVERLAY))
        .widget(new ImageWidget(91, 36, 14, 15, GuiTextures.TANK_ICON))
        .widget(new SlotWidget(containerInventory, 1, 90, 54, true, false)
            .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.OUT_SLOT_OVERLAY))
        .bindPlayerInventory(entityPlayer.inventory);
}
 
Example #8
Source File: WidgetFluidTank.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public WidgetFluidTank(IFluidTank tank, int posX, int posY, ForgeDirection direction)
{
	this.tank = tank;
	this.posX = posX;
	this.posY = posY;
	this.direction = direction;
}
 
Example #9
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);
}
 
Example #10
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 #11
Source File: TileEntityModuleMachine.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private MachineRecipe getActiveRecipe()
{
    NonNullList<ItemStack> input = invHandler.getInputStacks();
    List<FluidStack> inputFluid = Arrays.stream(supplier.inputTanks)
                                        .map(fluidSource::getFluidTank)
                                        .map(IFluidTank::getFluid)
                                        .collect(Collectors.toList());

    return MachineManager.findMatchingRecipe(supplier.recipeList, input, inputFluid, tile.getWorld());
}
 
Example #12
Source File: TileEntityModuleMachine.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private void extractInputFluids(MachineRecipe recipe)
{
    List<IFluidTank> remaining = Arrays.stream(supplier.inputTanks)
                                       .map(fluidSource::getFluidTank)
                                       .collect(Collectors.toCollection(LinkedList::new));

    ItemHelper.extractFluidsFromTanks(remaining, recipe.getFluidRecipeInput());
}
 
Example #13
Source File: GuiLogisticsBase.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(IGuiWidget widget){
    super.actionPerformed(widget);
    if(widget instanceof WidgetFluidStack) {
        boolean leftClick = Mouse.isButtonDown(0);
        boolean middleClick = Mouse.isButtonDown(2);
        boolean shift = PneumaticCraft.proxy.isSneakingInGui();
        IFluidTank tank = logistics.getTankFilter(widget.getID());
        if(tank.getFluidAmount() > 0) {
            if(middleClick) {
                logistics.setFilter(widget.getID(), (FluidStack)null);
            } else if(leftClick) {
                tank.drain(shift ? tank.getFluidAmount() / 2 : 1000, true);
                if(tank.getFluidAmount() < 1000) {
                    tank.drain(1000, true);
                }
            } else {
                tank.fill(new FluidStack(tank.getFluid().getFluid(), shift ? tank.getFluidAmount() : 1000), true);
            }
            NetworkHandler.sendToServer(new PacketSetLogisticsFluidFilterStack(logistics, tank.getFluid(), widget.getID()));
        } else {
            fluidSearchGui = new GuiLogisticsLiquidFilter(this);
            editingSlot = widget.getID();
            mc.displayGuiScreen(fluidSearchGui);
        }
    }
}
 
Example #14
Source File: GTTileMagicEnergyConverter.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onTankChanged(IFluidTank tank) {
	this.getNetwork().updateTileGuiField(this, "tank");
	this.inventory.set(2, ItemDisplayIcon.createWithFluidStack(this.tank.getFluid()));
	if (this.tank.getFluidAmount() == 0) {
		this.tank.setFluid(null);
		this.setStackInSlot(slotDisplay, ItemStack.EMPTY);
	}
}
 
Example #15
Source File: FluidTankList.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void deserializeNBT(NBTTagCompound nbt) {
    NBTTagList tanks = nbt.getTagList("Tanks", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < Math.min(fluidTanks.size(), nbt.getInteger("TankAmount")); i++) {
        NBTBase nbtTag = tanks.get(i);
        IFluidTank fluidTank = fluidTanks.get(i);
        if (fluidTank instanceof FluidTank) {
            ((FluidTank) fluidTank).readFromNBT((NBTTagCompound) nbtTag);
        } else if (fluidTank instanceof INBTSerializable) {
            ((INBTSerializable) fluidTank).deserializeNBT(nbtTag);
        }
    }
}
 
Example #16
Source File: FluidTankList.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IFluidTankProperties[] getTankProperties() {
    if (fluidTankProperties == null) {
        ArrayList<IFluidTankProperties> propertiesList = new ArrayList<>();
        for (IFluidTank fluidTank : fluidTanks) {
            if (fluidTank instanceof IFluidHandler) {
                IFluidHandler fluidHandler = (IFluidHandler) fluidTank;
                propertiesList.addAll(Arrays.asList(fluidHandler.getTankProperties()));
            }
        }
        this.fluidTankProperties = propertiesList.toArray(new IFluidTankProperties[0]);
    }
    return fluidTankProperties;
}
 
Example #17
Source File: AbstractRecipeLogic.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected int getMinTankCapacity(IMultipleTankHandler tanks) {
    if(tanks.getTanks() == 0) {
        return 0;
    }
    int result = Integer.MAX_VALUE;
    for(IFluidTank fluidTank : tanks.getFluidTanks()) {
        result = Math.min(fluidTank.getCapacity(), result);
    }
    return result;
}
 
Example #18
Source File: TileEntityPoweredInventoryFluid.java    From BigReactors with MIT License 5 votes vote down vote up
/**
 * @param direction tank side: UNKNOWN for default tank set
 * @return Array of {@link FluidTank}s contained in this ITankContainer for this direction
 */
public IFluidTank[] getTanks(ForgeDirection direction) {
	if(direction == ForgeDirection.UNKNOWN) {
		return tanks;
	}
	else {
		int exposure = getExposedTankFromSide(direction.ordinal());
		if(exposure == FLUIDTANK_NONE) {
			return kEmptyFluidTankList;
		}
		
		return tankExposureCache[exposure];
	}
}
 
Example #19
Source File: TileEntityKeroseneLamp.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@SideOnly(Side.CLIENT)
public IFluidTank getTank(){
    return tank;
}
 
Example #20
Source File: TileEntityModuleTank.java    From customstuff4 with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public IFluidTank getFluidTank(String name)
{
    return tank;
}
 
Example #21
Source File: WidgetFluidTank.java    From ExtraCells1 with MIT License 4 votes vote down vote up
public WidgetFluidTank(IFluidTank tank, int posX, int posY)
{
	this(tank, posX, posY, ForgeDirection.UNKNOWN);
}
 
Example #22
Source File: WidgetFluidStack.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
public WidgetFluidStack(int id, int x, int y, IFluidTank tank){
    super(id, x, y);
    this.tank = tank;
}
 
Example #23
Source File: AdapterFluidTank.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Class<?> getTargetClass() {
	return IFluidTank.class;
}
 
Example #24
Source File: SemiBlockLogistics.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public IFluidTank getTankFilter(int filterIndex){
    return fluidFilters[filterIndex];
}
 
Example #25
Source File: TileEntityPlasticMixer.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@SideOnly(Side.CLIENT)
public IFluidTank getFluidTank(){
    return tank;
}
 
Example #26
Source File: TileEntityLiquidCompressor.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@SideOnly(Side.CLIENT)
public IFluidTank getFluidTank(){
    return tank;
}
 
Example #27
Source File: AdapterFluidTank.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Returns info containing the capacity of the tank and the FluidStack it holds.")
public FluidTankInfo getInfo(IFluidTank tank) {
	return tank.getInfo();
}
 
Example #28
Source File: ElementFluidTankAdv.java    From SimplyJetpacks with MIT License 4 votes vote down vote up
public ElementFluidTankAdv(GuiBase gui, int posX, int posY, IFluidTank tank) {
    super(gui, posX, posY, tank);
    this.texture = new ResourceLocation(SimplyJetpacks.RESOURCE_PREFIX + "textures/gui/elements/fluidTank.png");
}
 
Example #29
Source File: WidgetTank.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public WidgetTank(int id, int x, int y, IFluidTank tank){
    super(id, x, y, 16, 64);
    this.tank = tank;
}
 
Example #30
Source File: WidgetFluidStack.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public WidgetFluidStack(int id, int x, int y, IFluidTank tank){
    super(id, x, y);
    this.tank = tank;
}