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)));
}
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));
}
}
}
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;
}
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());
}
}
}
}
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);
}
}
}
}
}
Aggregations