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 single reference to a tag, which holds the list of IDs,
  • A list of IDs (can also be represented as a single ID),
  • A list of inline elements (only supported by some sets, can also be represented as a single inline element), or,
  • A list with both IDs and inline elements (only supported by some sets).

Because HolderSets may 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.

GeyserHolderSets can be constructed using the empty(JavaRegistryKey), ofTag(JavaRegistryKey, Tag), and of(JavaRegistryKey, List) methods.
  • Method Details

    • empty

      public static <T> GeyserHolderSet<T> empty(JavaRegistryKey<T> registry)
      Constructs an empty GeyserHolderSet.
      Type Parameters:
      T - the type of the set
      Parameters:
      registry - the registry the set is bound to
      Returns:
      a new empty GeyserHolderSet for the given registry
    • ofTag

      public static <T> GeyserHolderSet<T> ofTag(JavaRegistryKey<T> registry, net.kyori.adventure.key.Key tag)
      Constructs a GeyserHolderSet for the given tag.
      Type Parameters:
      T - the type of the set
      Parameters:
      registry - the registry the set is bound to
      tag - the tag of the set
      Returns:
      the constructed GeyserHolderSet
    • ofTag

      public static <T> GeyserHolderSet<T> ofTag(JavaRegistryKey<T> registry, Tag<T> tag)
      Constructs a GeyserHolderSet for the given tag.
      Type Parameters:
      T - the type of the set
      Parameters:
      registry - the registry the set is bound to
      tag - the tag of the set
      Returns:
      the constructed GeyserHolderSet
    • of

      public static <T> GeyserHolderSet<T> of(JavaRegistryKey<T> registry, int id)
      Constructs a GeyserHolderSet holding a single registry reference (ID holder).
      Type Parameters:
      T - the type of the set
      Parameters:
      registry - the registry the set is bound to
      id - the single ID
      Returns:
      the constructed GeyserHolderSet
    • of

      public static <T> GeyserHolderSet<T> of(JavaRegistryKey<T> registry, T element)
      Constructs a GeyserHolderSet holding a single inline element (custom holder).
      Type Parameters:
      T - the type of the set
      Parameters:
      registry - the registry the set is bound to
      element - the single inline element
      Returns:
      the constructed GeyserHolderSet
    • of

      public static <T> GeyserHolderSet<T> of(JavaRegistryKey<T> registry, it.unimi.dsi.fastutil.ints.IntList ids)
      Constructs a GeyserHolderSet holding a list of registry reference (ID holder).
      Type Parameters:
      T - the type of the set
      Parameters:
      registry - the registry the set is bound to
      ids - the list of references
      Returns:
      the constructed GeyserHolderSet
    • of

      public static <T> GeyserHolderSet<T> of(JavaRegistryKey<T> registry, List<org.geysermc.mcprotocollib.protocol.data.game.Holder<T>> holders)
      Constructs a GeyserHolderSet holding a list of holders (either ID or custom holders).
      Type Parameters:
      T - the type of the set
      Parameters:
      registry - the registry the set is bound to
      holders - the list of holders
      Returns:
      the constructed GeyserHolderSet
    • fromMCPL

      public static <T> GeyserHolderSet<T> fromMCPL(JavaRegistryKey<T> registry, org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet holderSet)
      Constructs a GeyserHolderSet from a MCPL HolderSet.
      Type Parameters:
      T - the type of the set
      Parameters:
      registry - the registry the set is bound to
      holderSet - the MCPL HolderSet
      Returns:
      the constructed GeyserHolderSet
    • tag

      public Optional<Tag<T>> tag()
      Returns:
      the tag of this set, if this set is tag-based
    • contains

      public boolean contains(JavaRegistryProvider registries, @Nullable T object)
      Resolves this set, and checks if the given object is in it.
      Parameters:
      registries - the JavaRegistryProvider
      object - the object to check for
      Returns:
      true if the given object was in this set, false otherwise
    • resolveHolders

      public List<org.geysermc.mcprotocollib.protocol.data.game.Holder<T>> resolveHolders(JavaRegistryProvider registries)
      Resolves this set to a list of Holders, which may either be an Holder.IdHolder or a Holder.CustomHolder (depending on the registry, both can be present in the list at once).
      Parameters:
      registries - the JavaRegistryProvider
      Returns:
      the resolved set as a list of Holders
    • resolveRawHolders

      @Deprecated public int[] resolveRawHolders(JavaRegistryProvider registries)
      Deprecated.
      Resolves this set to a raw int-array of network IDs. This will not work for sets that have any inline holders.

      This method is deprecated: prefer using resolveHolders(JavaRegistryProvider) or resolve(JavaRegistryProvider) as much as possible, which also won't fail on inline holders.

      Parameters:
      registries - the GeyserSession
      Returns:
      the resolved set as a raw int-array of network IDs
    • resolve

      public List<T> resolve(JavaRegistryProvider registries)
      Resolves this set to a list of GeyserHolderSets. This calls resolveHolders(JavaRegistryProvider), and maps the Holder.IdHolders to a GeyserHolderSet using JavaRegistryKey.get(JavaRegistryProvider, int).
      Parameters:
      registries - the JavaRegistryProvider
      Returns:
      the resolved set as a list of Holders
    • readHolderSet

      public static <T> GeyserHolderSet<T> readHolderSet(GeyserSession session, JavaRegistryKey<T> registry, @Nullable Object holderSet)
      Reads a HolderSet from a NBT object. When the HolderSet contains inline elements, and a suitable reader exists in JavaRegistryReaders, that reader will be used to parse the inline element.
      Type Parameters:
      T - the type of the registry/HolderSet
      Parameters:
      session - the GeyserSession
      registry - the registry the HolderSet contains elements from
      holderSet - the HolderSet as an NBT object
    • readHolderSet

      public static <T> GeyserHolderSet<T> readHolderSet(JavaRegistryProvider registries, JavaRegistryKey<T> registry, @Nullable Object holderSet, Optional<GeyserSession> session)
      Reads a HolderSet from a NBT object. When the HolderSet contains inline elements, and a suitable reader exists in JavaRegistryReaders, that reader will be used to parse the inline element.

      This method should generally only be used in a JavaRegistryReader, where GeyserSessions may not always be present. Outside of registry readers, you should generally use readHolderSet(GeyserSession, JavaRegistryKey, Object).

      Type Parameters:
      T - the type of the registry/HolderSet
      Parameters:
      registries - the JavaRegistryProvider
      registry - the registry the HolderSet contains elements from
      holderSet - the HolderSet as an NBT object
      session - the GeyserSession as an Optional
    • registry

      public JavaRegistryKey<T> registry()
    • empty

      public boolean empty()