Search in sources :

Example 1 with MergedChemicalTank

use of mekanism.api.chemical.merged.MergedChemicalTank in project Mekanism by mekanism.

the class MergedChemicalInventorySlot method fill.

public static MergedChemicalInventorySlot<MergedChemicalTank> fill(MergedChemicalTank chemicalTank, @Nullable IContentsListener listener, int x, int y) {
    Objects.requireNonNull(chemicalTank, "Merged chemical tank cannot be null");
    Predicate<@NonNull ItemStack> gasExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(chemicalTank.getGasTank(), GasInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> infusionExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(chemicalTank.getInfusionTank(), InfusionInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> pigmentExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(chemicalTank.getPigmentTank(), PigmentInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> slurryExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(chemicalTank.getSlurryTank(), SlurryInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> gasInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(chemicalTank.getGasTank(), GasInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> infusionInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(chemicalTank.getInfusionTank(), InfusionInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> pigmentInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(chemicalTank.getPigmentTank(), PigmentInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> slurryInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(chemicalTank.getSlurryTank(), SlurryInventorySlot.getCapability(stack));
    return new MergedChemicalInventorySlot<>(chemicalTank, (stack, automationType) -> {
        if (automationType == AutomationType.MANUAL) {
            // Always allow the player to manually extract
            return true;
        }
        Current current = chemicalTank.getCurrent();
        if (current == Current.GAS) {
            return gasExtractPredicate.test(stack);
        } else if (current == Current.INFUSION) {
            return infusionExtractPredicate.test(stack);
        } else if (current == Current.PIGMENT) {
            return pigmentExtractPredicate.test(stack);
        } else if (current == Current.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) -> {
        Current current = chemicalTank.getCurrent();
        if (current == Current.GAS) {
            return gasInsertPredicate.test(stack);
        } else if (current == Current.INFUSION) {
            return infusionInsertPredicate.test(stack);
        } else if (current == Current.PIGMENT) {
            return pigmentInsertPredicate.test(stack);
        } else if (current == Current.SLURRY) {
            return slurryInsertPredicate.test(stack);
        }
        // Else the tank is empty, only allow it if one of the chemical insert predicates matches
        return gasInsertPredicate.test(stack) || infusionInsertPredicate.test(stack) || pigmentInsertPredicate.test(stack) || slurryInsertPredicate.test(stack);
    }, MergedChemicalInventorySlot::hasCapability, listener, x, y);
}
Also used : CurrentType(mekanism.common.capabilities.merged.MergedTank.CurrentType) Predicate(java.util.function.Predicate) MergedChemicalTank(mekanism.api.chemical.merged.MergedChemicalTank) AutomationType(mekanism.api.inventory.AutomationType) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) Objects(java.util.Objects) IContentsListener(mekanism.api.IContentsListener) BiPredicate(java.util.function.BiPredicate) ItemStack(net.minecraft.item.ItemStack) ContainerSlotType(mekanism.common.inventory.container.slot.ContainerSlotType) Capabilities(mekanism.common.capabilities.Capabilities) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current) Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) Nullable(javax.annotation.Nullable) ItemStack(net.minecraft.item.ItemStack) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Aggregations

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 NonNull (mekanism.api.annotations.NonNull)1 MergedChemicalTank (mekanism.api.chemical.merged.MergedChemicalTank)1 Current (mekanism.api.chemical.merged.MergedChemicalTank.Current)1 AutomationType (mekanism.api.inventory.AutomationType)1 Capabilities (mekanism.common.capabilities.Capabilities)1 CurrentType (mekanism.common.capabilities.merged.MergedTank.CurrentType)1 ContainerSlotType (mekanism.common.inventory.container.slot.ContainerSlotType)1 BasicInventorySlot (mekanism.common.inventory.slot.BasicInventorySlot)1 ItemStack (net.minecraft.item.ItemStack)1