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