Search in sources :

Example 1 with NonNull

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()));
}
Also used : NonNull(mekanism.api.annotations.NonNull) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) List(java.util.List) GasStack(mekanism.api.chemical.gas.GasStack)

Example 2 with NonNull

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);
}
Also used : CurrentType(mekanism.common.capabilities.merged.MergedTank.CurrentType) Predicate(java.util.function.Predicate) MergedChemicalTank(mekanism.api.chemical.merged.MergedChemicalTank) AutomationType(mekanism.api.inventory.AutomationType) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) Objects(java.util.Objects) IContentsListener(mekanism.api.IContentsListener) BiPredicate(java.util.function.BiPredicate) ItemStack(net.minecraft.item.ItemStack) ContainerSlotType(mekanism.common.inventory.container.slot.ContainerSlotType) Capabilities(mekanism.common.capabilities.Capabilities) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current) Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) Nullable(javax.annotation.Nullable) ItemStack(net.minecraft.item.ItemStack) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Example 3 with NonNull

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);
        }
    };
}
Also used : Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) ItemStack(net.minecraft.item.ItemStack)

Example 4 with NonNull

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);
        }
    };
}
Also used : Nonnull(javax.annotation.Nonnull) FluidStack(net.minecraftforge.fluids.FluidStack) NonNull(mekanism.api.annotations.NonNull)

Example 5 with NonNull

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();
}
Also used : SyncableInt(mekanism.common.inventory.container.sync.SyncableInt) IEnergyContainerHolder(mekanism.common.capabilities.holder.energy.IEnergyContainerHolder) IBoundingBlock(mekanism.common.tile.interfaces.IBoundingBlock) CompoundNBT(net.minecraft.nbt.CompoundNBT) WrappingComputerMethod(mekanism.common.integration.computer.annotation.WrappingComputerMethod) Direction(net.minecraft.util.Direction) Block(net.minecraft.block.Block) Capabilities(mekanism.common.capabilities.Capabilities) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) BasicCapabilityResolver(mekanism.common.capabilities.resolver.BasicCapabilityResolver) MekanismBlocks(mekanism.common.registries.MekanismBlocks) ListNBT(net.minecraft.nbt.ListNBT) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase) IChunkLoader(mekanism.common.lib.chunkloading.IChunkLoader) BlockEvent(net.minecraftforge.event.world.BlockEvent) EnergyInventorySlot(mekanism.common.inventory.slot.EnergyInventorySlot) NBTUtils(mekanism.common.util.NBTUtils) MinerEnergyContainer(mekanism.common.capabilities.energy.MinerEnergyContainer) Set(java.util.Set) MekanismUtils(mekanism.common.util.MekanismUtils) State(mekanism.common.content.miner.ThreadMinerSearch.State) ComputerException(mekanism.common.integration.computer.ComputerException) InventoryUtils(mekanism.common.util.InventoryUtils) RelativeSide(mekanism.api.RelativeSide) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) IFilter(mekanism.common.content.filter.IFilter) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) EnergyContainerHelper(mekanism.common.capabilities.holder.energy.EnergyContainerHelper) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SyncableBoolean(mekanism.common.inventory.container.sync.SyncableBoolean) ArrayList(java.util.ArrayList) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) LootContext(net.minecraft.loot.LootContext) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) DigitalMinerConfigContainer(mekanism.common.inventory.container.tile.DigitalMinerConfigContainer) Nullable(javax.annotation.Nullable) Long2ObjectMaps(it.unimi.dsi.fastutil.longs.Long2ObjectMaps) SyncableEnum(mekanism.common.inventory.container.sync.SyncableEnum) ISustainedData(mekanism.common.tile.interfaces.ISustainedData) SyncableItemStack(mekanism.common.inventory.container.sync.SyncableItemStack) BlockPos(net.minecraft.util.math.BlockPos) MinerFilter(mekanism.common.content.miner.MinerFilter) SyncableFilterList(mekanism.common.inventory.container.sync.list.SyncableFilterList) MekFakePlayer(mekanism.common.base.MekFakePlayer) MinecraftForge(net.minecraftforge.common.MinecraftForge) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) MekanismTags(mekanism.common.tags.MekanismTags) TileEntity(net.minecraft.tileentity.TileEntity) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) IInventorySlotHolder(mekanism.common.capabilities.holder.slot.IInventorySlotHolder) Finder(mekanism.common.lib.inventory.Finder) Action(mekanism.api.Action) SyncableRegistryEntry(mekanism.common.inventory.container.sync.SyncableRegistryEntry) ServerWorld(net.minecraft.world.server.ServerWorld) EnergyCompatUtils(mekanism.common.integration.energy.EnergyCompatUtils) Item(net.minecraft.item.Item) ThreadMinerSearch(mekanism.common.content.miner.ThreadMinerSearch) AutomationType(mekanism.api.inventory.AutomationType) ComputerIInventorySlotWrapper(mekanism.common.integration.computer.SpecialComputerMethodWrapper.ComputerIInventorySlotWrapper) InventorySlotHelper(mekanism.common.capabilities.holder.slot.InventorySlotHelper) ItemDataUtils(mekanism.common.util.ItemDataUtils) ITileFilterHolder(mekanism.common.tile.interfaces.ITileFilterHolder) WorldEvents(net.minecraftforge.common.util.Constants.WorldEvents) Enchantments(net.minecraft.enchantment.Enchantments) HashList(mekanism.common.lib.collection.HashList) Region(net.minecraft.world.Region) TileComponentChunkLoader(mekanism.common.tile.component.TileComponentChunkLoader) BlockState(net.minecraft.block.BlockState) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) IHasSortableFilters(mekanism.common.tile.interfaces.IHasSortableFilters) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Predicate(java.util.function.Predicate) StackUtils(mekanism.common.util.StackUtils) LootParameters(net.minecraft.loot.LootParameters) ChunkPos(net.minecraft.util.math.ChunkPos) Capability(net.minecraftforge.common.capabilities.Capability) Objects(java.util.Objects) List(java.util.List) BaseFilter(mekanism.common.content.filter.BaseFilter) Vector3d(net.minecraft.util.math.vector.Vector3d) NBTConstants(mekanism.api.NBTConstants) Optional(java.util.Optional) Vector3i(net.minecraft.util.math.vector.Vector3i) MekanismContainer(mekanism.common.inventory.container.MekanismContainer) Upgrade(mekanism.api.Upgrade) ObjectArraySet(it.unimi.dsi.fastutil.objects.ObjectArraySet) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) ITextComponent(net.minecraft.util.text.ITextComponent) BiPredicate(java.util.function.BiPredicate) FloatingLong(mekanism.api.math.FloatingLong) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) TransitRequest(mekanism.common.lib.inventory.TransitRequest) MekanismItems(mekanism.common.registries.MekanismItems) Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Items(net.minecraft.item.Items) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) NBT(net.minecraftforge.common.util.Constants.NBT) IInventorySlot(mekanism.api.inventory.IInventorySlot) WorldUtils(mekanism.common.util.WorldUtils) BitSet(java.util.BitSet) Collections(java.util.Collections) MekanismConfig(mekanism.common.config.MekanismConfig) UpgradeUtils(mekanism.common.util.UpgradeUtils) InventorySlotHelper(mekanism.common.capabilities.holder.slot.InventorySlotHelper) AutomationType(mekanism.api.inventory.AutomationType) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) ItemStack(net.minecraft.item.ItemStack) SyncableItemStack(mekanism.common.inventory.container.sync.SyncableItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

NonNull (mekanism.api.annotations.NonNull)12 Nonnull (javax.annotation.Nonnull)8 ItemStack (net.minecraft.item.ItemStack)8 List (java.util.List)6 BiPredicate (java.util.function.BiPredicate)4 Predicate (java.util.function.Predicate)4 Nullable (javax.annotation.Nullable)4 GasStack (mekanism.api.chemical.gas.GasStack)4 AutomationType (mekanism.api.inventory.AutomationType)4 BasicInventorySlot (mekanism.common.inventory.slot.BasicInventorySlot)4 Collections (java.util.Collections)3 NBTConstants (mekanism.api.NBTConstants)3 MekanismBlocks (mekanism.common.registries.MekanismBlocks)3 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 ChemicalStack (mekanism.api.chemical.ChemicalStack)2 ChemicalType (mekanism.api.chemical.ChemicalType)2 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)2 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)2 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)2