Class GeyserHolderSet<T>

java.lang.Object
org.geysermc.geyser.session.cache.tags.GeyserHolderSet<T>

public final class GeyserHolderSet<T> extends Object
Similar to vanilla Minecraft's HolderSets, stores either a tag, a list of IDs (this list can also be represented as a single ID in vanilla HolderSets), or a list of inline elements (only supported by some HolderSets, and can also be represented as a single inline element in vanilla HolderSets).

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 Details

    • GeyserHolderSet

      public GeyserHolderSet(JavaRegistryKey<T> registry, int @NonNull [] holders)
    • GeyserHolderSet

      public GeyserHolderSet(JavaRegistryKey<T> registry, @NonNull Tag<T> tagId)
    • GeyserHolderSet

      public GeyserHolderSet(JavaRegistryKey<T> registry, @NonNull List<T> inline)
  • Method Details

    • empty

      public static <T> GeyserHolderSet<T> empty(JavaRegistryKey<T> registry)
      Constructs an empty GeyserHolderSet.
    • fromHolderSet

      public static <T> GeyserHolderSet<T> fromHolderSet(JavaRegistryKey<T> registry, @NonNull org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet holderSet)
      Constructs a GeyserHolderSet from a MCPL HolderSet.
    • contains

      public boolean contains(@NonNull GeyserSession session, @Nullable T object)
    • resolve

      public List<T> resolve(GeyserSession session)
      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

      public int[] resolveRaw(TagCache tagCache)
      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. When reader is 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. When null, this method doesn't support reading inline HolderSets.
    • getRegistry

      public JavaRegistryKey<T> getRegistry()
    • getTag

      public @Nullable Tag<T> getTag()
    • getHolders

      public int @Nullable [] getHolders()
    • getInline

      public @Nullable List<T> getInline()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object