Search in sources :

Example 1 with IExtendedFluidTank

use of mekanism.api.fluid.IExtendedFluidTank in project Mekanism by mekanism.

the class GuiFluidGauge method getTooltipText.

@Override
public List<ITextComponent> getTooltipText() {
    if (dummy) {
        return Collections.singletonList(TextComponentUtil.build(dummyType));
    }
    IExtendedFluidTank tank = getTank();
    if (tank == null || tank.isEmpty()) {
        return Collections.singletonList(MekanismLang.EMPTY.translate());
    }
    int amount = tank.getFluidAmount();
    FluidStack fluidStack = tank.getFluid();
    if (amount == Integer.MAX_VALUE) {
        return Collections.singletonList(MekanismLang.GENERIC_STORED.translate(fluidStack, MekanismLang.INFINITE));
    }
    return Collections.singletonList(MekanismLang.GENERIC_STORED_MB.translate(fluidStack, TextUtils.format(amount)));
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank)

Example 2 with IExtendedFluidTank

use of mekanism.api.fluid.IExtendedFluidTank in project Mekanism by mekanism.

the class LookingAtUtils method displayFluid.

private static void displayFluid(LookingAtHelper info, IFluidHandler fluidHandler) {
    if (fluidHandler instanceof IMekanismFluidHandler) {
        IMekanismFluidHandler mekFluidHandler = (IMekanismFluidHandler) fluidHandler;
        for (IExtendedFluidTank fluidTank : mekFluidHandler.getFluidTanks(null)) {
            if (fluidTank instanceof FluidTankWrapper) {
                MergedTank mergedTank = ((FluidTankWrapper) fluidTank).getMergedTank();
                CurrentType currentType = mergedTank.getCurrentType();
                if (currentType != CurrentType.EMPTY && currentType != CurrentType.FLUID) {
                    // Skip if the tank is on a chemical
                    continue;
                }
            }
            addFluidInfo(info, fluidTank.getFluid(), fluidTank.getCapacity());
        }
    } else {
        // Fallback handling if it is not our fluid handler (probably never gets used)
        for (int tank = 0; tank < fluidHandler.getTanks(); tank++) {
            addFluidInfo(info, fluidHandler.getFluidInTank(tank), fluidHandler.getTankCapacity(tank));
        }
    }
}
Also used : IMekanismFluidHandler(mekanism.api.fluid.IMekanismFluidHandler) CurrentType(mekanism.common.capabilities.merged.MergedTank.CurrentType) MergedTank(mekanism.common.capabilities.merged.MergedTank) FluidTankWrapper(mekanism.common.capabilities.fluid.FluidTankWrapper) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank)

Example 3 with IExtendedFluidTank

use of mekanism.api.fluid.IExtendedFluidTank in project Mekanism by mekanism.

the class ISideConfiguration method getActiveDataType.

@Nullable
default DataType getActiveDataType(Object container) {
    ConfigInfo info = null;
    TileComponentConfig config = getConfig();
    if (container instanceof IGasTank && config.supports(TransmissionType.GAS)) {
        info = config.getConfig(TransmissionType.GAS);
    } else if (container instanceof IInfusionTank && config.supports(TransmissionType.INFUSION)) {
        info = config.getConfig(TransmissionType.INFUSION);
    } else if (container instanceof IPigmentTank && config.supports(TransmissionType.PIGMENT)) {
        info = config.getConfig(TransmissionType.PIGMENT);
    } else if (container instanceof ISlurryTank && config.supports(TransmissionType.SLURRY)) {
        info = config.getConfig(TransmissionType.SLURRY);
    } else if (container instanceof IExtendedFluidTank && config.supports(TransmissionType.FLUID)) {
        info = config.getConfig(TransmissionType.FLUID);
    } else if (container instanceof IInventorySlot && config.supports(TransmissionType.ITEM)) {
        info = config.getConfig(TransmissionType.ITEM);
    }
    if (info != null) {
        List<DataType> types = info.getDataTypeForContainer(container);
        int count = types.size();
        // of <= size - 1 to cut down slightly on the calculations
        if (count > 0 && count < info.getSupportedDataTypes().size()) {
            return types.get(0);
        }
    }
    return null;
}
Also used : IInventorySlot(mekanism.api.inventory.IInventorySlot) IPigmentTank(mekanism.api.chemical.pigment.IPigmentTank) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) IGasTank(mekanism.api.chemical.gas.IGasTank) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) ISlurryTank(mekanism.api.chemical.slurry.ISlurryTank) Nullable(javax.annotation.Nullable)

Example 4 with IExtendedFluidTank

use of mekanism.api.fluid.IExtendedFluidTank in project Mekanism by mekanism.

the class TileComponentEjector method eject.

/**
 * @apiNote Ensure that it can eject before calling this method.
 */
private void eject(TransmissionType type, ConfigInfo info) {
    // Used to keep track of tanks to what sides they output to
    Map<Object, Set<Direction>> outputData = null;
    for (DataType dataType : info.getSupportedDataTypes()) {
        if (dataType.canOutput()) {
            ISlotInfo slotInfo = info.getSlotInfo(dataType);
            if (slotInfo != null) {
                Set<Direction> outputSides = info.getSidesForData(dataType);
                if (!outputSides.isEmpty()) {
                    if (outputData == null) {
                        // Lazy init outputData
                        outputData = new HashMap<>();
                    }
                    if (type.isChemical() && slotInfo instanceof ChemicalSlotInfo) {
                        for (IChemicalTank<?, ?> tank : ((ChemicalSlotInfo<?, ?, ?>) slotInfo).getTanks()) {
                            if (!tank.isEmpty() && (canTankEject == null || canTankEject.test(tank))) {
                                outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    } else if (type == TransmissionType.FLUID && slotInfo instanceof FluidSlotInfo) {
                        for (IExtendedFluidTank tank : ((FluidSlotInfo) slotInfo).getTanks()) {
                            if (!tank.isEmpty()) {
                                outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    } else if (type == TransmissionType.ENERGY && slotInfo instanceof EnergySlotInfo) {
                        for (IEnergyContainer container : ((EnergySlotInfo) slotInfo).getContainers()) {
                            if (!container.isEmpty()) {
                                outputData.computeIfAbsent(container, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    }
                }
            }
        }
    }
    if (outputData != null && !outputData.isEmpty()) {
        for (Map.Entry<Object, Set<Direction>> entry : outputData.entrySet()) {
            if (type.isChemical()) {
                ChemicalUtil.emit(entry.getValue(), (IChemicalTank<?, ?>) entry.getKey(), tile, chemicalEjectRate.getAsLong());
            } else if (type == TransmissionType.FLUID) {
                FluidUtils.emit(entry.getValue(), (IExtendedFluidTank) entry.getKey(), tile, fluidEjectRate.getAsInt());
            } else if (type == TransmissionType.ENERGY) {
                IEnergyContainer container = (IEnergyContainer) entry.getKey();
                CableUtils.emit(entry.getValue(), container, tile, energyEjectRate == null ? container.getMaxEnergy() : energyEjectRate.get());
            }
        }
    }
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) LongSupplier(java.util.function.LongSupplier) SyncableInt(mekanism.common.inventory.container.sync.SyncableInt) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) CompoundNBT(net.minecraft.nbt.CompoundNBT) Direction(net.minecraft.util.Direction) FluidSlotInfo(mekanism.common.tile.component.config.slot.FluidSlotInfo) TileTransitRequest(mekanism.common.lib.inventory.TileTransitRequest) Map(java.util.Map) EnumSet(java.util.EnumSet) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase) EnumMap(java.util.EnumMap) NBTUtils(mekanism.common.util.NBTUtils) Predicate(java.util.function.Predicate) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) Set(java.util.Set) List(java.util.List) ComputerException(mekanism.common.integration.computer.ComputerException) InventoryUtils(mekanism.common.util.InventoryUtils) RelativeSide(mekanism.api.RelativeSide) ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) NBTConstants(mekanism.api.NBTConstants) ChemicalUtil(mekanism.common.util.ChemicalUtil) EnumColor(mekanism.api.text.EnumColor) CableUtils(mekanism.common.util.CableUtils) SyncableBoolean(mekanism.common.inventory.container.sync.SyncableBoolean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ISpecificContainerTracker(mekanism.common.inventory.container.MekanismContainer.ISpecificContainerTracker) ChemicalSlotInfo(mekanism.common.tile.component.config.slot.ChemicalSlotInfo) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) IEnergyContainer(mekanism.api.energy.IEnergyContainer) Nonnull(javax.annotation.Nonnull) IntSupplier(java.util.function.IntSupplier) Nullable(javax.annotation.Nullable) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) EnumUtils(mekanism.common.util.EnumUtils) DataType(mekanism.common.tile.component.config.DataType) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo) TransporterUtils(mekanism.common.util.TransporterUtils) FluidUtils(mekanism.common.util.FluidUtils) NBT(net.minecraftforge.common.util.Constants.NBT) EnergySlotInfo(mekanism.common.tile.component.config.slot.EnergySlotInfo) WorldUtils(mekanism.common.util.WorldUtils) TileEntity(net.minecraft.tileentity.TileEntity) IChemicalTank(mekanism.api.chemical.IChemicalTank) MekanismConfig(mekanism.common.config.MekanismConfig) FloatingLongSupplier(mekanism.api.math.FloatingLongSupplier) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) FluidSlotInfo(mekanism.common.tile.component.config.slot.FluidSlotInfo) EnumSet(java.util.EnumSet) Set(java.util.Set) EnergySlotInfo(mekanism.common.tile.component.config.slot.EnergySlotInfo) Direction(net.minecraft.util.Direction) ChemicalSlotInfo(mekanism.common.tile.component.config.slot.ChemicalSlotInfo) IEnergyContainer(mekanism.api.energy.IEnergyContainer) DataType(mekanism.common.tile.component.config.DataType) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Example 5 with IExtendedFluidTank

use of mekanism.api.fluid.IExtendedFluidTank in project Mekanism by mekanism.

the class ItemBlockFluidTank method fillItemCategory.

@Override
public void fillItemCategory(@Nonnull ItemGroup group, @Nonnull NonNullList<ItemStack> items) {
    super.fillItemCategory(group, items);
    if (allowdedIn(group)) {
        FluidTankTier tier = Attribute.getTier(getBlock(), FluidTankTier.class);
        if (tier == FluidTankTier.CREATIVE && MekanismConfig.general.prefilledFluidTanks.get()) {
            int capacity = tier.getStorage();
            for (Fluid fluid : ForgeRegistries.FLUIDS.getValues()) {
                // Only add sources
                if (fluid.isSource(fluid.defaultFluidState())) {
                    IExtendedFluidTank dummyTank = BasicFluidTank.create(capacity, null);
                    // Manually handle filling it as capabilities are not necessarily loaded yet
                    dummyTank.setStack(new FluidStack(fluid, dummyTank.getCapacity()));
                    ItemStack stack = new ItemStack(this);
                    ItemDataUtils.setList(stack, NBTConstants.FLUID_TANKS, DataHandlerUtils.writeContainers(Collections.singletonList(dummyTank)));
                    items.add(stack);
                }
            }
        }
    }
}
Also used : FluidTankTier(mekanism.common.tier.FluidTankTier) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraft.fluid.Fluid) ItemStack(net.minecraft.item.ItemStack) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank)

Aggregations

IExtendedFluidTank (mekanism.api.fluid.IExtendedFluidTank)9 Nonnull (javax.annotation.Nonnull)4 Nullable (javax.annotation.Nullable)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NBTConstants (mekanism.api.NBTConstants)3 IMekanismFluidHandler (mekanism.api.fluid.IMekanismFluidHandler)3 ItemStack (net.minecraft.item.ItemStack)3 Map (java.util.Map)2 Set (java.util.Set)2 IntSupplier (java.util.function.IntSupplier)2 Action (mekanism.api.Action)2 DataHandlerUtils (mekanism.api.DataHandlerUtils)2 IGasTank (mekanism.api.chemical.gas.IGasTank)2 IInfusionTank (mekanism.api.chemical.infuse.IInfusionTank)2 IPigmentTank (mekanism.api.chemical.pigment.IPigmentTank)2 ISlurryTank (mekanism.api.chemical.slurry.ISlurryTank)2 IEnergyContainer (mekanism.api.energy.IEnergyContainer)2 IInventorySlot (mekanism.api.inventory.IInventorySlot)2 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)2