Class GeyserHolderSet<T>
Because HolderSets utilise tags, when loading a HolderSet, Geyser must store tags for the registry the HolderSet is for. This is done for all registries registered in
JavaRegistries.
Use the readHolderSet(org.geysermc.geyser.session.GeyserSession, org.geysermc.geyser.session.cache.registry.JavaRegistryKey<T>, java.lang.Object) method to easily read a HolderSet from NBT sent by a server. To turn the HolderSet into a list of network IDs, use the resolveRaw(org.geysermc.geyser.session.cache.TagCache) method.
To turn the HolderSet into a list of objects, use the resolve(org.geysermc.geyser.session.GeyserSession) method.
Note that the resolveRaw(TagCache) method will fail for inline HolderSets, since inline elements are not registered and as such have no network ID.
-
Constructor Summary
ConstructorsConstructorDescriptionGeyserHolderSet(JavaRegistryKey<T> registry, int @NonNull [] holders) GeyserHolderSet(JavaRegistryKey<T> registry, @NonNull List<T> inline) GeyserHolderSet(JavaRegistryKey<T> registry, @NonNull Tag<T> tagId) -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(@NonNull GeyserSession session, @Nullable T object) static <T> GeyserHolderSet<T> empty(JavaRegistryKey<T> registry) Constructs an emptyGeyserHolderSet.booleanstatic <T> GeyserHolderSet<T> fromHolderSet(JavaRegistryKey<T> registry, @NonNull org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet holderSet) Constructs aGeyserHolderSetfrom a MCPL HolderSet.int @Nullable []getTag()inthashCode()static <T> GeyserHolderSet<T> readHolderSet(JavaRegistryKey<T> registry, @Nullable Object holderSet, ToIntFunction<net.kyori.adventure.key.Key> idMapper) Reads a HolderSet from a NBT object.static <T> GeyserHolderSet<T> readHolderSet(JavaRegistryKey<T> registry, @Nullable Object holderSet, ToIntFunction<net.kyori.adventure.key.Key> idMapper, @Nullable Function<org.cloudburstmc.nbt.NbtMap, T> reader) Reads a HolderSet from a NBT object.static <T> GeyserHolderSet<T> readHolderSet(GeyserSession session, JavaRegistryKey<T> registry, @Nullable Object holderSet) Reads a HolderSet from a NBT object.resolve(GeyserSession session) Resolves the HolderSet, and automatically maps the network IDs to their respective object types.int[]resolveRaw(TagCache tagCache) Resolves the HolderSet into a list of network IDs.toString()
-
Constructor Details
-
GeyserHolderSet
-
GeyserHolderSet
-
GeyserHolderSet
-
-
Method Details
-
empty
Constructs an emptyGeyserHolderSet. -
fromHolderSet
public static <T> GeyserHolderSet<T> fromHolderSet(JavaRegistryKey<T> registry, @NonNull org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet holderSet) Constructs aGeyserHolderSetfrom a MCPL HolderSet. -
contains
-
resolve
Resolves the HolderSet, and automatically maps the network IDs to their respective object types. If the HolderSet is a list of IDs, this will be returned. If it is a tag, the tag will be resolved from the tag cache. If it is an inline HolderSet, the list of inline elements will be returned.- Returns:
- the HolderSet turned into a list of objects.
-
resolveRaw
Resolves the HolderSet into a list of network IDs. If the HolderSet is a list of IDs, this will be returned. If it is a tag, the tag will be resolved from the tag cache.If the HolderSet is a list of inline elements, this method will throw! Inline elements are not registered and as such do not have a network ID.
- Returns:
- the HolderSet turned into a list of network IDs.
- Throws:
IllegalStateException- when the HolderSet is a list of inline elements.
-
readHolderSet
public static <T> GeyserHolderSet<T> readHolderSet(GeyserSession session, JavaRegistryKey<T> registry, @Nullable Object holderSet) Reads a HolderSet from a NBT object. Does not support reading HolderSets that can hold inline values.Uses
JavaRegistryKey.networkId(GeyserSession, Key)to resolve registry keys to network IDs.- Parameters:
session- the Geyser session.registry- the registry the HolderSet contains IDs from.holderSet- the HolderSet as a NBT object.
-
readHolderSet
public static <T> GeyserHolderSet<T> readHolderSet(JavaRegistryKey<T> registry, @Nullable Object holderSet, ToIntFunction<net.kyori.adventure.key.Key> idMapper) Reads a HolderSet from a NBT object. Does not support reading HolderSets that can hold inline values.- Parameters:
registry- the registry the HolderSet contains IDs from.holderSet- the HolderSet as a NBT object.idMapper- a function that maps a key in this registry to its respective network ID.
-
readHolderSet
public static <T> GeyserHolderSet<T> readHolderSet(JavaRegistryKey<T> registry, @Nullable Object holderSet, ToIntFunction<net.kyori.adventure.key.Key> idMapper, @Nullable Function<org.cloudburstmc.nbt.NbtMap, T> reader) Reads a HolderSet from a NBT object. Whenreaderis not null, this method can read HolderSets with inline registry elements as well, using the passed reader to decode registry elements.- Parameters:
registry- the registry the HolderSet contains IDs from.holderSet- the HolderSet as a NBT object.idMapper- a function that maps a key in this registry to its respective network ID.reader- a function that reads an object in the HolderSet's registry, serialised as NBT. Whennull, this method doesn't support reading inline HolderSets.
-
getRegistry
-
getTag
-
getHolders
public int @Nullable [] getHolders() -
getInline
-
equals
-
hashCode
public int hashCode() -
toString
-