use of mekanism.api.IContentsListener 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.IContentsListener in project Mekanism by mekanism.
the class GasInventorySlot method fillOrConvert.
/**
* Fills the tank from this item OR converts the given item to a gas
*/
public static GasInventorySlot fillOrConvert(IGasTank gasTank, Supplier<World> worldSupplier, @Nullable IContentsListener listener, int x, int y) {
Objects.requireNonNull(gasTank, "Gas tank cannot be null");
Objects.requireNonNull(worldSupplier, "World supplier cannot be null");
Function<ItemStack, GasStack> potentialConversionSupplier = stack -> getPotentialConversion(worldSupplier.get(), stack);
return new GasInventorySlot(gasTank, worldSupplier, getFillOrConvertExtractPredicate(gasTank, GasInventorySlot::getCapability, potentialConversionSupplier), getFillOrConvertInsertPredicate(gasTank, GasInventorySlot::getCapability, potentialConversionSupplier), stack -> {
if (stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).isPresent()) {
// Note: we mark all gas items as valid and have a more restrictive insert check so that we allow full tanks when they are done being filled
return true;
}
// Allow gas conversion of items that have a gas that is valid
GasStack gasConversion = getPotentialConversion(worldSupplier.get(), stack);
return !gasConversion.isEmpty() && gasTank.isValid(gasConversion);
}, listener, x, y);
}
use of mekanism.api.IContentsListener 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);
}
use of mekanism.api.IContentsListener in project Mekanism by mekanism.
the class InfusionInventorySlot method fillOrConvert.
/**
* Fills the tank from this item OR converts the given item to an infusion type
*/
public static InfusionInventorySlot fillOrConvert(IInfusionTank infusionTank, Supplier<World> worldSupplier, @Nullable IContentsListener listener, int x, int y) {
Objects.requireNonNull(infusionTank, "Infusion tank cannot be null");
Objects.requireNonNull(worldSupplier, "World supplier cannot be null");
Function<ItemStack, InfusionStack> potentialConversionSupplier = stack -> getPotentialConversion(worldSupplier.get(), stack);
return new InfusionInventorySlot(infusionTank, worldSupplier, getFillOrConvertExtractPredicate(infusionTank, InfusionInventorySlot::getCapability, potentialConversionSupplier), getFillOrConvertInsertPredicate(infusionTank, InfusionInventorySlot::getCapability, potentialConversionSupplier), stack -> {
if (stack.getCapability(Capabilities.INFUSION_HANDLER_CAPABILITY).isPresent()) {
// Note: we mark all infusion items as valid and have a more restrictive insert check so that we allow full tanks when they are done being filled
return true;
}
// Allow infusion conversion of items that have an infusion that is valid
InfusionStack conversion = getPotentialConversion(worldSupplier.get(), stack);
return !conversion.isEmpty() && infusionTank.isValid(conversion);
}, listener, x, y);
}
Aggregations