use of mekanism.common.capabilities.merged.MergedTank in project Mekanism by mekanism.
the class LookingAtUtils method displayFluid.
private static void displayFluid(LookingAtHelper info, IFluidHandler fluidHandler) {
if (fluidHandler instanceof IMekanismFluidHandler) {
IMekanismFluidHandler mekFluidHandler = (IMekanismFluidHandler) fluidHandler;
for (IExtendedFluidTank fluidTank : mekFluidHandler.getFluidTanks(null)) {
if (fluidTank instanceof FluidTankWrapper) {
MergedTank mergedTank = ((FluidTankWrapper) fluidTank).getMergedTank();
CurrentType currentType = mergedTank.getCurrentType();
if (currentType != CurrentType.EMPTY && currentType != CurrentType.FLUID) {
// Skip if the tank is on a chemical
continue;
}
}
addFluidInfo(info, fluidTank.getFluid(), fluidTank.getCapacity());
}
} else {
// Fallback handling if it is not our fluid handler (probably never gets used)
for (int tank = 0; tank < fluidHandler.getTanks(); tank++) {
addFluidInfo(info, fluidHandler.getFluidInTank(tank), fluidHandler.getTankCapacity(tank));
}
}
}
use of mekanism.common.capabilities.merged.MergedTank 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