Class AEKey

java.lang.Object
appeng.api.stacks.AEKey
Direct Known Subclasses:
AEFluidKey, AEItemKey

public abstract class AEKey extends Object
Uniquely identifies something that "stacks" within an ME inventory.

For example for items, this is the combination of an Item and optional CompoundTag. To account for common indexing scenarios, a key is (optionally) split into a primary and secondary component, which serves two purposes:

  • Fuzzy cards allow setting filters for the primary component of a key, i.e. for an Item, while disregarding the compound tag.
  • When indexing resources, it is usually assumed that indexing by the primary key alone offers a good trade-off between memory usage and lookup speed.
  • Field Details

    • TYPE_FIELD

      public static final String TYPE_FIELD
      See Also:
    • MAP_CODEC

      public static final com.mojang.serialization.MapCodec<AEKey> MAP_CODEC
    • CODEC

      public static final com.mojang.serialization.Codec<AEKey> CODEC
    • STREAM_CODEC

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,AEKey> STREAM_CODEC
    • OPTIONAL_STREAM_CODEC

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,AEKey> OPTIONAL_STREAM_CODEC
  • Constructor Details

    • AEKey

      public AEKey()
  • Method Details

    • writeOptionalKey

      public static void writeOptionalKey(net.minecraft.network.RegistryFriendlyByteBuf buffer, @Nullable @Nullable AEKey key)
      Writes a generic, nullable key to the given buffer.
    • writeKey

      public static void writeKey(net.minecraft.network.RegistryFriendlyByteBuf buffer, AEKey key)
    • readOptionalKey

      @Nullable public static @Nullable AEKey readOptionalKey(net.minecraft.network.RegistryFriendlyByteBuf buffer)
    • readKey

      @Nullable public static @Nullable AEKey readKey(net.minecraft.network.RegistryFriendlyByteBuf buffer)
    • fromTagGeneric

      @Nullable public static @Nullable AEKey fromTagGeneric(net.minecraft.core.HolderLookup.Provider registries, net.minecraft.nbt.CompoundTag tag)
    • toTagGeneric

      public final net.minecraft.nbt.CompoundTag toTagGeneric(net.minecraft.core.HolderLookup.Provider registries)
      Same as toTag(HolderLookup.Provider), but includes type information so that fromTagGeneric(HolderLookup.Provider, CompoundTag) can restore this particular type of key withot knowing the actual type beforehand.
    • getAmountPerUnit

      public final int getAmountPerUnit()
      How much of this key is in one unit (i.e. one bucket). This is used for display purposes where the technical amount is not user-readable (i.e. a bucket of fluid has amount 1000 on Forge and 81000 on Fabric, but we want to show it as 1 bucket, hence this method would return 1000 on Forge and 81000 on Fabric for AEFluidKey).
    • getUnitSymbol

      @Nullable public final @Nullable String getUnitSymbol()
    • getAmountPerOperation

      public final int getAmountPerOperation()
      See Also:
    • getAmountPerByte

      public final int getAmountPerByte()
      See Also:
    • formatAmount

      public String formatAmount(long amount, AmountFormat format)
      See Also:
    • getType

      public abstract AEKeyType getType()
      Returns:
      An object giving additional properties about the type of key.
    • dropSecondary

      public abstract AEKey dropSecondary()
      Returns:
      This object if it has no secondary component, otherwise a copy of this resource key with the secondary component removed.
    • toTag

      public abstract net.minecraft.nbt.CompoundTag toTag(net.minecraft.core.HolderLookup.Provider registries)
      Serialized keys MUST NOT contain keys that start with #, because this prefix can be used to add additional data into the same tag as the key.
    • getPrimaryKey

      public abstract Object getPrimaryKey()
    • getFuzzySearchValue

      public int getFuzzySearchValue()
      Returns:
      If getFuzzySearchMaxValue() is greater than 0, this is the value in the range of [0,getFuzzyModeMaxValue] used to index keys by. Used by fuzzy mode search with percentage ranges.
    • getFuzzySearchMaxValue

      public int getFuzzySearchMaxValue()
      Returns:
      The upper bound for values returned by getFuzzySearchValue(). If it is equal to 0, no fuzzy range-search is possible for this type of key.
    • fuzzyEquals

      public final boolean fuzzyEquals(AEKey other, FuzzyMode fuzzyMode)
      Tests if this and the given AE key are in the same fuzzy partition given a specific fuzzy matching mode.
    • matches

      @Contract("null -> false") public final boolean matches(@Nullable @Nullable GenericStack stack)
      Checks if the given stack has the same key as this.
      Returns:
      False if stack is null, otherwise true iff the stacks key is equal to this.
    • getModId

      public String getModId()
      Returns:
      The ID of the mod this resource belongs to.
    • getId

      public abstract net.minecraft.resources.ResourceLocation getId()
      Returns:
      The ID of the resource identified by this key.
    • writeToPacket

      public abstract void writeToPacket(net.minecraft.network.RegistryFriendlyByteBuf data)
    • wrapForDisplayOrFilter

      public net.minecraft.world.item.ItemStack wrapForDisplayOrFilter()
      Wraps a key in an ItemStack that can be unwrapped into a key later.
    • supportsFuzzyRangeSearch

      public final boolean supportsFuzzyRangeSearch()
      True to indicate that this type of AEKey supports range-based fuzzy search using getFuzzySearchValue() and getFuzzySearchMaxValue().

      For items this is used for damage-based search and filtering.

    • getDisplayName

      public final net.minecraft.network.chat.Component getDisplayName()
    • computeDisplayName

      protected abstract net.minecraft.network.chat.Component computeDisplayName()
      Compute the display name, which is used to sort by name in client terminal. Will be cached by getDisplayName().
    • addDrops

      public abstract void addDrops(long amount, List<net.minecraft.world.item.ItemStack> drops, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Adds the drops if the container holding this key is broken, such as an interface holding stacks. Item stacks should be placed in the list and not spawned directly into the world
      Parameters:
      amount - Amount to drop
      drops - Drop list to append to, in case of ItemStack drops
      level - World where the stacks were being held
      pos - Position where the stacks were being held
    • isTagged

      public boolean isTagged(net.minecraft.tags.TagKey<?> tag)
      If the underlying resource supports tagging, this method checks if the resource represented by this key is tagged by the given tag.
    • get

      @Nullable public <T> T get(net.minecraft.core.component.DataComponentType<T> type)
      Get a data component attached to this key. It might be null.
    • hasComponents

      public abstract boolean hasComponents()
      Returns:
      true if this key has *any* components attached.