Search in sources :

Example 1 with MergedTank

use of mekanism.common.capabilities.merged.MergedTank 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 2 with MergedTank

use of mekanism.common.capabilities.merged.MergedTank in project Mekanism by mekanism.

the class HybridInventorySlot method outputOrFill.

public static HybridInventorySlot outputOrFill(MergedTank mergedTank, @Nullable IContentsListener listener, int x, int y) {
    Objects.requireNonNull(mergedTank, "Merged tank cannot be null");
    Predicate<@NonNull ItemStack> gasExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getGasTank(), GasInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> infusionExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getInfusionTank(), InfusionInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> pigmentExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getPigmentTank(), PigmentInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> slurryExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getSlurryTank(), SlurryInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> gasInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getGasTank(), GasInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> infusionInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getInfusionTank(), InfusionInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> pigmentInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getPigmentTank(), PigmentInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> slurryInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getSlurryTank(), SlurryInventorySlot.getCapability(stack));
    return new HybridInventorySlot(mergedTank, (stack, automationType) -> {
        if (automationType == AutomationType.MANUAL) {
            // Always allow the player to manually extract
            return true;
        }
        CurrentType currentType = mergedTank.getCurrentType();
        if (currentType == CurrentType.FLUID) {
            // Always allow extracting from a "fluid output" slot
            return true;
        } else if (currentType == CurrentType.GAS) {
            return gasExtractPredicate.test(stack);
        } else if (currentType == CurrentType.INFUSION) {
            return infusionExtractPredicate.test(stack);
        } else if (currentType == CurrentType.PIGMENT) {
            return pigmentExtractPredicate.test(stack);
        } else if (currentType == CurrentType.SLURRY) {
            return slurryExtractPredicate.test(stack);
        }
        // Else the tank is empty, check all our extraction predicates
        return gasExtractPredicate.test(stack) && infusionExtractPredicate.test(stack) && pigmentExtractPredicate.test(stack) && slurryExtractPredicate.test(stack);
    }, (stack, automationType) -> {
        CurrentType currentType = mergedTank.getCurrentType();
        if (currentType == CurrentType.FLUID) {
            // Only allow inserting internally for "fluid output" slots
            return automationType == AutomationType.INTERNAL;
        } else if (currentType == CurrentType.GAS) {
            return gasInsertPredicate.test(stack);
        } else if (currentType == CurrentType.INFUSION) {
            return infusionInsertPredicate.test(stack);
        } else if (currentType == CurrentType.PIGMENT) {
            return pigmentInsertPredicate.test(stack);
        } else if (currentType == CurrentType.SLURRY) {
            return slurryInsertPredicate.test(stack);
        }
        // Else the tank is empty, if the item is a fluid handler, and it is an internal check allow it
        if (automationType == AutomationType.INTERNAL && FluidUtil.getFluidHandler(stack).isPresent()) {
            return true;
        }
        // otherwise, only allow it if one of the chemical insert predicates matches
        return gasInsertPredicate.test(stack) || infusionInsertPredicate.test(stack) || pigmentInsertPredicate.test(stack) || slurryInsertPredicate.test(stack);
    }, HybridInventorySlot::hasCapability, listener, x, y);
}
Also used : FluidUtil(net.minecraftforge.fluids.FluidUtil) MergedChemicalInventorySlot(mekanism.common.inventory.slot.chemical.MergedChemicalInventorySlot) CurrentType(mekanism.common.capabilities.merged.MergedTank.CurrentType) Predicate(java.util.function.Predicate) InfusionInventorySlot(mekanism.common.inventory.slot.chemical.InfusionInventorySlot) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) AutomationType(mekanism.api.inventory.AutomationType) ChemicalInventorySlot(mekanism.common.inventory.slot.chemical.ChemicalInventorySlot) PigmentInventorySlot(mekanism.common.inventory.slot.chemical.PigmentInventorySlot) SlurryInventorySlot(mekanism.common.inventory.slot.chemical.SlurryInventorySlot) CompoundNBT(net.minecraft.nbt.CompoundNBT) MergedTank(mekanism.common.capabilities.merged.MergedTank) Objects(java.util.Objects) IContentsListener(mekanism.api.IContentsListener) BiPredicate(java.util.function.BiPredicate) ItemStack(net.minecraft.item.ItemStack) GasInventorySlot(mekanism.common.inventory.slot.chemical.GasInventorySlot) Capabilities(mekanism.common.capabilities.Capabilities) NBTConstants(mekanism.api.NBTConstants) Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) Nullable(javax.annotation.Nullable) SlurryInventorySlot(mekanism.common.inventory.slot.chemical.SlurryInventorySlot) CurrentType(mekanism.common.capabilities.merged.MergedTank.CurrentType) GasInventorySlot(mekanism.common.inventory.slot.chemical.GasInventorySlot) ItemStack(net.minecraft.item.ItemStack) InfusionInventorySlot(mekanism.common.inventory.slot.chemical.InfusionInventorySlot) PigmentInventorySlot(mekanism.common.inventory.slot.chemical.PigmentInventorySlot)

Aggregations

IExtendedFluidTank (mekanism.api.fluid.IExtendedFluidTank)2 MergedTank (mekanism.common.capabilities.merged.MergedTank)2 CurrentType (mekanism.common.capabilities.merged.MergedTank.CurrentType)2 Objects (java.util.Objects)1 BiPredicate (java.util.function.BiPredicate)1 Predicate (java.util.function.Predicate)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 IContentsListener (mekanism.api.IContentsListener)1 NBTConstants (mekanism.api.NBTConstants)1 NonNull (mekanism.api.annotations.NonNull)1 IMekanismFluidHandler (mekanism.api.fluid.IMekanismFluidHandler)1 AutomationType (mekanism.api.inventory.AutomationType)1 Capabilities (mekanism.common.capabilities.Capabilities)1 FluidTankWrapper (mekanism.common.capabilities.fluid.FluidTankWrapper)1 ChemicalInventorySlot (mekanism.common.inventory.slot.chemical.ChemicalInventorySlot)1 GasInventorySlot (mekanism.common.inventory.slot.chemical.GasInventorySlot)1 InfusionInventorySlot (mekanism.common.inventory.slot.chemical.InfusionInventorySlot)1 MergedChemicalInventorySlot (mekanism.common.inventory.slot.chemical.MergedChemicalInventorySlot)1 PigmentInventorySlot (mekanism.common.inventory.slot.chemical.PigmentInventorySlot)1