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