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