Class StructuredDataContainer

java.lang.Object
com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer

public final class StructuredDataContainer extends Object
  • Constructor Details

    • StructuredDataContainer

      public StructuredDataContainer(Map<StructuredDataKey<?>,StructuredData<?>> data)
    • StructuredDataContainer

      public StructuredDataContainer(StructuredData<?>[] dataArray)
    • StructuredDataContainer

      public StructuredDataContainer()
  • Method Details

    • get

      public <T> @Nullable StructuredData<T> get(StructuredDataKey<T> key)
      Returns structured data by id if present.
      Type Parameters:
      T - data type
      Parameters:
      key - serializer id
      Returns:
      structured data
    • getNonEmpty

      public <T> @Nullable StructuredData<T> getNonEmpty(StructuredDataKey<T> key)
      Returns structured data by id if not empty.
      Type Parameters:
      T - data type
      Parameters:
      key - serializer id
      Returns:
      structured data if not empty
    • computeIfAbsent

      public <T> StructuredData<T> computeIfAbsent(StructuredDataKey<T> key, Function<StructuredDataKey<T>,T> mappingFunction)
      Returns structured data by id if not empty, or creates it.
      Type Parameters:
      T - data type
      Parameters:
      key - serializer id
      mappingFunction - function to create structured data if not present
      Returns:
      structured data if not empty
    • updateIfPresent

      public <T> @Nullable StructuredData<T> updateIfPresent(StructuredDataKey<T> key, Function<T,T> mappingFunction)
      Updates and returns the structured data by id if not empty.
      Type Parameters:
      T - data type
      Parameters:
      key - serializer id
      mappingFunction - function to update existing data
      Returns:
      updated structured data if not empty
    • set

      public <T> void set(StructuredDataKey<T> key, T value)
    • replaceKey

      public <T> void replaceKey(StructuredDataKey<T> key, StructuredDataKey<T> toKey)
    • replace

      public <T, V> void replace(StructuredDataKey<T> key, StructuredDataKey<V> toKey, Function<T,V> valueMapper)
    • set

      public void set(StructuredDataKey<Unit> key)
    • addEmpty

      public void addEmpty(StructuredDataKey<?> key)
    • remove

      public <T> @Nullable StructuredData<T> remove(StructuredDataKey<T> key)
      Removes and returns structured data by the given key.
      Type Parameters:
      T - data type
      Parameters:
      key - serializer key
      Returns:
      removed structured data
    • contains

      public boolean contains(StructuredDataKey<?> key)
    • setIdLookup

      public void setIdLookup(Protocol<?,?,?,?> protocol, boolean mappedNames)
      Sets the lookup for serializer ids. Required to call most of the other methods.
      Parameters:
      protocol - protocol to retreive the id of the serializer from
      mappedNames - if the names are mapped (true if structures from the mapped version are added, false for the unmapped version)
    • updateIds

      public void updateIds(Protocol<?,?,?,?> protocol, it.unimi.dsi.fastutil.ints.Int2IntFunction rewriter)
    • copy

      public StructuredDataContainer copy()
    • data

      public Map<StructuredDataKey<?>,StructuredData<?>> data()
    • toString

      public String toString()
      Overrides:
      toString in class Object