use of mekanism.api.annotations.NonNull in project Mekanism by mekanism.
the class PressurizedReactionRecipeCategory method setRecipe.
@Override
public void setRecipe(IRecipeLayout recipeLayout, PressurizedReactionRecipe recipe, IIngredients ingredients) {
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
initItem(itemStacks, 0, true, inputItem, recipe.getInputSolid().getRepresentations());
Pair<List<@NonNull ItemStack>, @NonNull GasStack> outputDefinition = recipe.getOutputDefinition();
initItem(itemStacks, 1, false, outputItem, outputDefinition.getLeft());
initFluid(recipeLayout.getFluidStacks(), 0, true, inputFluid, recipe.getInputFluid().getRepresentations());
IGuiIngredientGroup<GasStack> gasStacks = recipeLayout.getIngredientsGroup(MekanismJEI.TYPE_GAS);
initChemical(gasStacks, 0, true, inputGas, recipe.getInputGas().getRepresentations());
initChemical(gasStacks, 1, false, outputGas, Collections.singletonList(outputDefinition.getRight()));
}
use of mekanism.api.annotations.NonNull 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.annotations.NonNull in project Mekanism by mekanism.
the class InputHelper method getInputHandler.
/**
* Wrap an inventory slot into an {@link IInputHandler}.
*
* @param slot Slot to wrap.
*/
public static IInputHandler<@NonNull ItemStack> getInputHandler(IInventorySlot slot) {
Objects.requireNonNull(slot, "Slot cannot be null.");
return new IInputHandler<@NonNull ItemStack>() {
@Nonnull
@Override
public ItemStack getInput() {
return slot.getStack();
}
@Nonnull
@Override
public ItemStack getRecipeInput(InputIngredient<@NonNull ItemStack> recipeIngredient) {
ItemStack input = getInput();
if (input.isEmpty()) {
// All recipes currently require that we have an input. If we don't then return that we failed
return ItemStack.EMPTY;
}
return recipeIngredient.getMatchingInstance(input);
}
@Override
public void use(@Nonnull ItemStack recipeInput, int operations) {
if (operations == 0) {
// Just exit if we are somehow here at zero operations
return;
}
if (!recipeInput.isEmpty()) {
int amount = recipeInput.getCount() * operations;
logMismatchedStackSize(slot.shrinkStack(amount, Action.EXECUTE), amount);
}
}
@Override
public int operationsCanSupport(@Nonnull ItemStack recipeInput, int currentMax, int usageMultiplier) {
if (currentMax <= 0 || usageMultiplier <= 0) {
// Short circuit that if we already can't perform any operations or don't want to use any, just return
return currentMax;
}
if (recipeInput.isEmpty()) {
// If the input is empty that means there is no ingredient that matches
return 0;
}
// TODO: Simulate?
return Math.min(getInput().getCount() / (recipeInput.getCount() * usageMultiplier), currentMax);
}
};
}
use of mekanism.api.annotations.NonNull in project Mekanism by mekanism.
the class InputHelper method getInputHandler.
/**
* Wrap a fluid tank into an {@link IInputHandler}.
*
* @param tank Tank to wrap.
*/
public static IInputHandler<@NonNull FluidStack> getInputHandler(IExtendedFluidTank tank) {
Objects.requireNonNull(tank, "Tank cannot be null.");
return new IInputHandler<@NonNull FluidStack>() {
@Nonnull
@Override
public FluidStack getInput() {
return tank.getFluid();
}
@Nonnull
@Override
public FluidStack getRecipeInput(InputIngredient<@NonNull FluidStack> recipeIngredient) {
FluidStack input = getInput();
if (input.isEmpty()) {
// All recipes currently require that we have an input. If we don't then return that we failed
return FluidStack.EMPTY;
}
return recipeIngredient.getMatchingInstance(input);
}
@Override
public void use(@Nonnull FluidStack recipeInput, int operations) {
if (operations == 0 || recipeInput.isEmpty()) {
// or if something went wrong, this if should never really be true if we got to finishProcessing
return;
}
FluidStack inputFluid = getInput();
if (!inputFluid.isEmpty()) {
int amount = recipeInput.getAmount() * operations;
logMismatchedStackSize(tank.shrinkStack(amount, Action.EXECUTE), amount);
}
}
@Override
public int operationsCanSupport(@Nonnull FluidStack recipeInput, int currentMax, int usageMultiplier) {
if (currentMax <= 0 || usageMultiplier <= 0) {
// Short circuit that if we already can't perform any operations or don't want to use any, just return
return currentMax;
}
// Test to make sure we can even perform a single operation. This is akin to !recipe.test(inputFluid)
if (recipeInput.isEmpty()) {
// If the input is empty that means there is no ingredient that matches
return 0;
}
// TODO: Simulate the drain?
return Math.min(getInput().getAmount() / (recipeInput.getAmount() * usageMultiplier), currentMax);
}
};
}
use of mekanism.api.annotations.NonNull in project Mekanism by mekanism.
the class TileEntityDigitalMiner method getInitialInventory.
@Nonnull
@Override
protected IInventorySlotHolder getInitialInventory() {
mainSlots = new ArrayList<>();
InventorySlotHelper builder = InventorySlotHelper.forSide(this::getDirection, side -> side == RelativeSide.TOP, side -> side == RelativeSide.BACK);
// Allow insertion manually or internally, or if it is a replace stack
BiPredicate<@NonNull ItemStack, @NonNull AutomationType> canInsert = (stack, automationType) -> automationType != AutomationType.EXTERNAL || isReplaceTarget(stack.getItem());
// Allow extraction if it is manual or if it is a replace stack
BiPredicate<@NonNull ItemStack, @NonNull AutomationType> canExtract = (stack, automationType) -> automationType == AutomationType.MANUAL || !isReplaceTarget(stack.getItem());
for (int slotY = 0; slotY < 3; slotY++) {
for (int slotX = 0; slotX < 9; slotX++) {
BasicInventorySlot slot = BasicInventorySlot.at(canExtract, canInsert, this, 8 + slotX * 18, 92 + slotY * 18);
builder.addSlot(slot, RelativeSide.BACK, RelativeSide.TOP);
mainSlots.add(slot);
}
}
builder.addSlot(energySlot = EnergyInventorySlot.fillOrConvert(energyContainer, this::getLevel, this, 152, 20));
return builder.build();
}
Aggregations