Package appeng.api.stacks
Class AEKey
java.lang.Object
appeng.api.stacks.AEKey
- Direct Known Subclasses:
AEFluidKey,AEItemKey
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<AEKey> static final com.mojang.serialization.MapCodec<AEKey> static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, AEKey> static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, AEKey> static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddDrops(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.protected abstract net.minecraft.network.chat.ComponentCompute the display name, which is used to sort by name in client terminal.abstract AEKeyformatAmount(long amount, AmountFormat format) static @Nullable AEKeyfromTagGeneric(net.minecraft.core.HolderLookup.Provider registries, net.minecraft.nbt.CompoundTag tag) final booleanfuzzyEquals(AEKey other, FuzzyMode fuzzyMode) Tests if this and the given AE key are in the same fuzzy partition given a specific fuzzy matching mode.<T> Tget(net.minecraft.core.component.DataComponentType<T> type) Get a data component attached to this key.final intfinal intfinal intHow much of this key is in one unit (i.e.final net.minecraft.network.chat.Componentintintabstract net.minecraft.resources.ResourceLocationgetId()getModId()abstract Objectabstract AEKeyTypegetType()final @Nullable Stringabstract booleanbooleanisTagged(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.final booleanmatches(@Nullable GenericStack stack) Checks if the given stack has the same key as this.static @Nullable AEKeyreadKey(net.minecraft.network.RegistryFriendlyByteBuf buffer) static @Nullable AEKeyreadOptionalKey(net.minecraft.network.RegistryFriendlyByteBuf buffer) Tries reading a key written usingwriteOptionalKey(net.minecraft.network.RegistryFriendlyByteBuf, appeng.api.stacks.AEKey).final booleanTrue to indicate that this type ofAEKeysupports range-based fuzzy search usinggetFuzzySearchValue()andgetFuzzySearchMaxValue().abstract net.minecraft.nbt.CompoundTagtoTag(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.final net.minecraft.nbt.CompoundTagtoTagGeneric(net.minecraft.core.HolderLookup.Provider registries) Same astoTag(HolderLookup.Provider), but includes type information so thatfromTagGeneric(HolderLookup.Provider, CompoundTag)can restore this particular type of key withot knowing the actual type beforehand.net.minecraft.world.item.ItemStackWraps a key in an ItemStack that can be unwrapped into a key later.static voidstatic voidwriteOptionalKey(net.minecraft.network.RegistryFriendlyByteBuf buffer, @Nullable AEKey key) Writes a generic, nullable key to the given buffer.abstract voidwriteToPacket(net.minecraft.network.RegistryFriendlyByteBuf data)
-
Field Details
-
TYPE_FIELD
- See Also:
-
MAP_CODEC
-
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
-
readOptionalKey
@Nullable public static @Nullable AEKey readOptionalKey(net.minecraft.network.RegistryFriendlyByteBuf buffer) Tries reading a key written usingwriteOptionalKey(net.minecraft.network.RegistryFriendlyByteBuf, appeng.api.stacks.AEKey). -
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 astoTag(HolderLookup.Provider), but includes type information so thatfromTagGeneric(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
-
getAmountPerOperation
public final int getAmountPerOperation()- See Also:
-
getAmountPerByte
public final int getAmountPerByte()- See Also:
-
formatAmount
- See Also:
-
getType
- Returns:
- An object giving additional properties about the type of key.
-
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
-
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
Tests if this and the given AE key are in the same fuzzy partition given a specific fuzzy matching mode. -
matches
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
- 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 ofAEKeysupports range-based fuzzy search usinggetFuzzySearchValue()andgetFuzzySearchMaxValue(). 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 bygetDisplayName(). -
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 dropdrops- Drop list to append to, in case ofItemStackdropslevel- World where the stacks were being heldpos- 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.
-