use of mekanism.common.inventory.slot.chemical.PigmentInventorySlot in project Mekanism by mekanism.
the class HybridInventorySlot method outputOrFill.
public static HybridInventorySlot outputOrFill(MergedTank mergedTank, @Nullable IContentsListener listener, int x, int y) {
Objects.requireNonNull(mergedTank, "Merged tank cannot be null");
Predicate<@NonNull ItemStack> gasExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getGasTank(), GasInventorySlot::getCapability);
Predicate<@NonNull ItemStack> infusionExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getInfusionTank(), InfusionInventorySlot::getCapability);
Predicate<@NonNull ItemStack> pigmentExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getPigmentTank(), PigmentInventorySlot::getCapability);
Predicate<@NonNull ItemStack> slurryExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getSlurryTank(), SlurryInventorySlot::getCapability);
Predicate<@NonNull ItemStack> gasInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getGasTank(), GasInventorySlot.getCapability(stack));
Predicate<@NonNull ItemStack> infusionInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getInfusionTank(), InfusionInventorySlot.getCapability(stack));
Predicate<@NonNull ItemStack> pigmentInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getPigmentTank(), PigmentInventorySlot.getCapability(stack));
Predicate<@NonNull ItemStack> slurryInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getSlurryTank(), SlurryInventorySlot.getCapability(stack));
return new HybridInventorySlot(mergedTank, (stack, automationType) -> {
if (automationType == AutomationType.MANUAL) {
// Always allow the player to manually extract
return true;
}
CurrentType currentType = mergedTank.getCurrentType();
if (currentType == CurrentType.FLUID) {
// Always allow extracting from a "fluid output" slot
return true;
} else if (currentType == CurrentType.GAS) {
return gasExtractPredicate.test(stack);
} else if (currentType == CurrentType.INFUSION) {
return infusionExtractPredicate.test(stack);
} else if (currentType == CurrentType.PIGMENT) {
return pigmentExtractPredicate.test(stack);
} else if (currentType == CurrentType.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) -> {
CurrentType currentType = mergedTank.getCurrentType();
if (currentType == CurrentType.FLUID) {
// Only allow inserting internally for "fluid output" slots
return automationType == AutomationType.INTERNAL;
} else if (currentType == CurrentType.GAS) {
return gasInsertPredicate.test(stack);
} else if (currentType == CurrentType.INFUSION) {
return infusionInsertPredicate.test(stack);
} else if (currentType == CurrentType.PIGMENT) {
return pigmentInsertPredicate.test(stack);
} else if (currentType == CurrentType.SLURRY) {
return slurryInsertPredicate.test(stack);
}
// Else the tank is empty, if the item is a fluid handler, and it is an internal check allow it
if (automationType == AutomationType.INTERNAL && FluidUtil.getFluidHandler(stack).isPresent()) {
return true;
}
// otherwise, only allow it if one of the chemical insert predicates matches
return gasInsertPredicate.test(stack) || infusionInsertPredicate.test(stack) || pigmentInsertPredicate.test(stack) || slurryInsertPredicate.test(stack);
}, HybridInventorySlot::hasCapability, listener, x, y);
}
Aggregations