Search in sources :

Example 1 with Current

use of mekanism.api.chemical.merged.MergedChemicalTank.Current 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)

Example 2 with Current

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

the class TileEntityChemicalTank method onUpdateServer.

@Override
protected void onUpdateServer() {
    super.onUpdateServer();
    drainSlot.drainChemicalTanks();
    fillSlot.fillChemicalTanks();
    if (dumping != GasMode.IDLE && tier != ChemicalTankTier.CREATIVE) {
        Current current = chemicalTank.getCurrent();
        if (current != Current.EMPTY) {
            IChemicalTank<?, ?> currentTank = getCurrentTank(current);
            if (dumping == GasMode.DUMPING) {
                currentTank.shrinkStack(tier.getStorage() / 400, Action.EXECUTE);
            } else {
                // dumping == GasMode.DUMPING_EXCESS
                long target = MathUtils.clampToLong(currentTank.getCapacity() * MekanismConfig.general.dumpExcessKeepRatio.get());
                long stored = currentTank.getStored();
                if (target < stored) {
                    // Dump excess that we need to get to the target (capping at our eject rate for how much we can dump at once)
                    currentTank.shrinkStack(Math.min(stored - target, tier.getOutput()), Action.EXECUTE);
                }
            }
        }
    }
}
Also used : Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Example 3 with Current

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

the class BoxedPressurizedTube method takeShare.

@Override
public void takeShare() {
    if (hasTransmitterNetwork()) {
        BoxedChemicalNetwork transmitterNetwork = getTransmitterNetwork();
        Current networkCurrent = transmitterNetwork.chemicalTank.getCurrent();
        if (networkCurrent != Current.EMPTY && !saveShare.isEmpty()) {
            ChemicalStack<?> chemicalStack = saveShare.getChemicalStack();
            long amount = chemicalStack.getAmount();
            MekanismUtils.logMismatchedStackSize(transmitterNetwork.chemicalTank.getTankFromCurrent(networkCurrent).shrinkStack(amount, Action.EXECUTE), amount);
            setStackClearOthers(chemicalStack, chemicalTank.getTankFromCurrent(networkCurrent));
        }
    }
}
Also used : BoxedChemicalNetwork(mekanism.common.content.network.BoxedChemicalNetwork) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Example 4 with Current

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

the class BoxedChemicalNetwork method isCompatibleWith.

@Override
public boolean isCompatibleWith(BoxedChemicalNetwork other) {
    if (super.isCompatibleWith(other)) {
        Current current = chemicalTank.getCurrent();
        if (current == Current.EMPTY) {
            return true;
        }
        Current otherCurrent = other.chemicalTank.getCurrent();
        return otherCurrent == Current.EMPTY || current == otherCurrent && chemicalTank.getTankFromCurrent(current).getType() == other.chemicalTank.getTankFromCurrent(otherCurrent).getType();
    }
    return false;
}
Also used : Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Example 5 with Current

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

the class BoxedChemicalNetwork method clampBuffer.

@Override
public void clampBuffer() {
    Current current = chemicalTank.getCurrent();
    if (current != Current.EMPTY) {
        long capacity = getCapacity();
        IChemicalTank<?, ?> tank = chemicalTank.getTankFromCurrent(current);
        if (tank.getStored() > capacity) {
            MekanismUtils.logMismatchedStackSize(tank.setStackSize(capacity, Action.EXECUTE), capacity);
        }
    }
}
Also used : Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Aggregations

Current (mekanism.api.chemical.merged.MergedChemicalTank.Current)12 Nonnull (javax.annotation.Nonnull)2 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 BiPredicate (java.util.function.BiPredicate)1 Predicate (java.util.function.Predicate)1 Nullable (javax.annotation.Nullable)1 IContentsListener (mekanism.api.IContentsListener)1 NonNull (mekanism.api.annotations.NonNull)1 IChemicalTank (mekanism.api.chemical.IChemicalTank)1 BoxedChemical (mekanism.api.chemical.merged.BoxedChemical)1 MergedChemicalTank (mekanism.api.chemical.merged.MergedChemicalTank)1 AutomationType (mekanism.api.inventory.AutomationType)1 GuiInnerScreen (mekanism.client.gui.element.GuiInnerScreen)1 GuiGasMode (mekanism.client.gui.element.button.GuiGasMode)1 Capabilities (mekanism.common.capabilities.Capabilities)1 CurrentType (mekanism.common.capabilities.merged.MergedTank.CurrentType)1 BoxedChemicalNetwork (mekanism.common.content.network.BoxedChemicalNetwork)1