use of mekanism.api.chemical.IChemicalTank in project Mekanism by mekanism.
the class TileComponentEjector method eject.
/**
* @apiNote Ensure that it can eject before calling this method.
*/
private void eject(TransmissionType type, ConfigInfo info) {
// Used to keep track of tanks to what sides they output to
Map<Object, Set<Direction>> outputData = null;
for (DataType dataType : info.getSupportedDataTypes()) {
if (dataType.canOutput()) {
ISlotInfo slotInfo = info.getSlotInfo(dataType);
if (slotInfo != null) {
Set<Direction> outputSides = info.getSidesForData(dataType);
if (!outputSides.isEmpty()) {
if (outputData == null) {
// Lazy init outputData
outputData = new HashMap<>();
}
if (type.isChemical() && slotInfo instanceof ChemicalSlotInfo) {
for (IChemicalTank<?, ?> tank : ((ChemicalSlotInfo<?, ?, ?>) slotInfo).getTanks()) {
if (!tank.isEmpty() && (canTankEject == null || canTankEject.test(tank))) {
outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
}
}
} else if (type == TransmissionType.FLUID && slotInfo instanceof FluidSlotInfo) {
for (IExtendedFluidTank tank : ((FluidSlotInfo) slotInfo).getTanks()) {
if (!tank.isEmpty()) {
outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
}
}
} else if (type == TransmissionType.ENERGY && slotInfo instanceof EnergySlotInfo) {
for (IEnergyContainer container : ((EnergySlotInfo) slotInfo).getContainers()) {
if (!container.isEmpty()) {
outputData.computeIfAbsent(container, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
}
}
}
}
}
}
}
if (outputData != null && !outputData.isEmpty()) {
for (Map.Entry<Object, Set<Direction>> entry : outputData.entrySet()) {
if (type.isChemical()) {
ChemicalUtil.emit(entry.getValue(), (IChemicalTank<?, ?>) entry.getKey(), tile, chemicalEjectRate.getAsLong());
} else if (type == TransmissionType.FLUID) {
FluidUtils.emit(entry.getValue(), (IExtendedFluidTank) entry.getKey(), tile, fluidEjectRate.getAsInt());
} else if (type == TransmissionType.ENERGY) {
IEnergyContainer container = (IEnergyContainer) entry.getKey();
CableUtils.emit(entry.getValue(), container, tile, energyEjectRate == null ? container.getMaxEnergy() : energyEjectRate.get());
}
}
}
}
use of mekanism.api.chemical.IChemicalTank 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);
}
}
}
}
Aggregations