Search in sources :

Example 6 with Current

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

the class BoxedChemicalNetwork method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (needsUpdate) {
        MinecraftForge.EVENT_BUS.post(new ChemicalTransferEvent(this, lastChemical));
        needsUpdate = false;
    }
    Current current = chemicalTank.getCurrent();
    if (current == Current.EMPTY) {
        prevTransferAmount = 0;
    } else {
        IChemicalTank<?, ?> tank = chemicalTank.getTankFromCurrent(current);
        prevTransferAmount = tickEmit(tank.getStack());
        MekanismUtils.logMismatchedStackSize(tank.shrinkStack(prevTransferAmount, Action.EXECUTE), prevTransferAmount);
    }
}
Also used : Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Example 7 with Current

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

the class BoxedChemicalNetwork method absorbBuffer.

@Override
public void absorbBuffer(BoxedPressurizedTube transmitter) {
    BoxedChemicalStack chemical = transmitter.releaseShare();
    if (!chemical.isEmpty()) {
        Current current = chemicalTank.getCurrent();
        ChemicalStack<?> chemicalStack = chemical.getChemicalStack();
        if (current == Current.EMPTY) {
            setStack(chemicalStack.copy(), chemicalTank.getTankForType(chemical.getChemicalType()));
        } else if (ChemicalUtil.compareTypes(chemical.getChemicalType(), current)) {
            IChemicalTank<?, ?> tank = chemicalTank.getTankFromCurrent(current);
            if (chemicalStack.getType() == tank.getType()) {
                long amount = chemicalStack.getAmount();
                MekanismUtils.logMismatchedStackSize(tank.growStack(amount, Action.EXECUTE), amount);
            }
        }
    }
}
Also used : IChemicalTank(mekanism.api.chemical.IChemicalTank) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack)

Example 8 with Current

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

the class BoxedChemicalNetwork method onContentsChanged.

@Override
public void onContentsChanged() {
    markDirty();
    Current current = chemicalTank.getCurrent();
    BoxedChemical type = current == Current.EMPTY ? BoxedChemical.EMPTY : BoxedChemical.box(chemicalTank.getTankFromCurrent(current).getType());
    if (!lastChemical.equals(type)) {
        // If the chemical type does not match update it, and mark that we need an update
        if (!type.isEmpty()) {
            lastChemical = type;
        }
        needsUpdate = true;
    }
}
Also used : BoxedChemical(mekanism.api.chemical.merged.BoxedChemical) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Example 9 with Current

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

the class BoxedChemicalNetwork method setLastChemical.

public void setLastChemical(@Nonnull BoxedChemical chemical) {
    if (chemical.isEmpty()) {
        Current current = chemicalTank.getCurrent();
        if (current != Current.EMPTY) {
            chemicalTank.getTankFromCurrent(current).setEmpty();
        }
    } else {
        lastChemical = chemical;
        setStackClearOthers(lastChemical.getChemical().getStack(1), chemicalTank.getTankForType(lastChemical.getChemicalType()));
    }
}
Also used : Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Example 10 with Current

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

the class BoxedChemicalNetwork method adoptTransmittersAndAcceptorsFrom.

@Override
public List<BoxedPressurizedTube> adoptTransmittersAndAcceptorsFrom(BoxedChemicalNetwork net) {
    float oldScale = currentScale;
    long oldCapacity = getCapacity();
    List<BoxedPressurizedTube> transmittersToUpdate = super.adoptTransmittersAndAcceptorsFrom(net);
    // Merge the chemical scales
    long capacity = getCapacity();
    currentScale = Math.min(1, capacity == 0 ? 0 : (currentScale * oldCapacity + net.currentScale * net.capacity) / capacity);
    if (isRemote()) {
        if (isTankEmpty()) {
            adoptBuffer(net);
        }
    } else {
        if (!net.isTankEmpty()) {
            if (isTankEmpty()) {
                adoptBuffer(net);
            } else {
                Current current = chemicalTank.getCurrent();
                Current netCurrent = net.chemicalTank.getCurrent();
                if (current == netCurrent) {
                    // If the chemical types match (then compare the chemicals themselves)
                    IChemicalTank<?, ?> tank = chemicalTank.getTankFromCurrent(current);
                    IChemicalTank<?, ?> netTank = net.chemicalTank.getTankFromCurrent(current);
                    if (tank.getType() == netTank.getType()) {
                        long amount = netTank.getStored();
                        MekanismUtils.logMismatchedStackSize(tank.growStack(amount, Action.EXECUTE), amount);
                    }
                    netTank.setEmpty();
                } else {
                    Mekanism.logger.error("Incompatible chemical networks merged: {}, {}.", current, netCurrent);
                }
            }
        }
        if (oldScale != currentScale) {
            // We want to make sure we update to the scale change
            needsUpdate = true;
        }
    }
    return transmittersToUpdate;
}
Also used : BoxedPressurizedTube(mekanism.common.content.network.transmitter.BoxedPressurizedTube) 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