Record Class EnvironmentAttributeMap

java.lang.Object
java.lang.Record
dev.wyck.environment.attribute.EnvironmentAttributeMap

@NullMarked @AsOf("2.1.0") public record EnvironmentAttributeMap(Map<ResourceKey, EnvironmentAttribute<?>> attributes, Map<ResourceKey, EnvironmentAttributeMap.Modification<?,?>> modifications, List<EnvironmentAttributeMap.Pending<?>> pending) extends Record
A collection of EnvironmentAttributes.
Since:
1.1.0
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • attributes

      @AsOf("2.1.0") public Map<ResourceKey, EnvironmentAttribute<?>> attributes()
      Returns the fully resolved directly set attribute map.
      Returns:
      the resolved attributes, in an unmodifiable map
      Since:
      2.1.0
    • values

      @AsOf("2.1.0") public Collection<EnvironmentAttribute<?>> values()
      Returns the directly set wrapped attributes as a collection. Order matches insertion order.
      Returns:
      the directly set wrapped attributes
      Since:
      2.1.0
    • modifications

      @AsOf("3.3.0") public Map<ResourceKey, EnvironmentAttributeMap.Modification<?,?>> modifications()
      Returns the modifiers in this map, indexed by their attribute keys.
      Returns:
      the attribute modifiers
      Since:
      3.3.0
    • modification

      @AsOf("3.3.0") public <V,A> @Nullable EnvironmentAttributeMap.Modification<V,A> modification(EnvironmentAttributeSupplier<V> supplier)
      Returns the modifier for the given attribute, or null if that attribute is directly set or absent.
      Type Parameters:
      V - the value type of the attribute
      A - the argument type of the modifier
      Parameters:
      supplier - the attribute supplier
      Returns:
      the modifier associated with the attribute, or null if absent
      Since:
      3.3.0
    • get

      @AsOf("3.0.0") public <V> @Nullable V get(EnvironmentAttributeSupplier<V> supplier)
      Returns the value of the given attribute, or null if it is not present. Pending values take precedence over resolved ones, and the most recently set pending value wins.
      Type Parameters:
      V - the type of the attribute
      Parameters:
      supplier - the attribute supplier
      Returns:
      the directly set value associated with the supplier, or null if modified or absent
      Since:
      3.0.0
    • empty

      @AsOf("1.1.0") public boolean empty()
      Returns:
      true if the map is empty, false otherwise.
      Since:
      1.1.0
    • toBuilder

      @AsOf("2.1.0") public EnvironmentAttributeMap.Builder toBuilder()
      Returns:
      a new builder pre-populated with this map's attributes.
      Since:
      2.1.0
    • with

      @AsOf("2.1.0") public <V> EnvironmentAttributeMap with(EnvironmentAttributeSupplier<V> supplier, @Nullable V value)
      Creates a new WrappedEnvironmentAttributeMap with the given attribute added.
      Type Parameters:
      V - the type of the attribute
      Parameters:
      supplier - the attribute supplier
      value - the value to set
      Returns:
      a new WrappedEnvironmentAttributeMap with the given attribute added
      Since:
      2.1.0
    • withModifier

      @AsOf("3.3.0") public <V,A> EnvironmentAttributeMap withModifier(EnvironmentAttributeSupplier<V> supplier, AttributeOperation operation, A argument)
      Creates a new map with a modifier for the given attribute.

      The operation and argument use the same types as an attribute timeline track. For example, multiplying a float attribute takes a Float argument, while AttributeOperation.ALPHA_BLEND takes an AlphaValue for float attributes.

      Type Parameters:
      V - the value type of the attribute
      A - the argument type of the modifier
      Parameters:
      supplier - the attribute supplier
      operation - the operation applied to the attribute
      argument - the operation argument
      Returns:
      a new map containing the modifier
      Since:
      3.3.0
    • with

      @AsOf("2.1.0") public EnvironmentAttributeMap with(FriendlyColorSupplier supplier, @Nullable String hex)
      Creates a new WrappedEnvironmentAttributeMap with the given color attribute added.
      Parameters:
      supplier - the color attribute supplier
      hex - the hex value (e.g. "#FF10F0")
      Returns:
      a new WrappedEnvironmentAttributeMap with the given color attribute added
      Since:
      2.1.0
    • with

      @AsOf("3.4.0") public EnvironmentAttributeMap with(EnvironmentAttributeMap source)
      Creates a new map containing every entry from this map plus every entry from the given map.

      Unlike EnvironmentAttributeMap.Builder.merge(EnvironmentAttributeMap), colliding keys do not throw: any attribute, modifier, or pending value in source fully replaces the entry for that key in this map, regardless of which form it took here.

      Parameters:
      source - the map whose entries take precedence
      Returns:
      a new map with the given map's entries applied over this one
      Since:
      3.4.0
    • builder

      @AsOf("1.1.0") public static EnvironmentAttributeMap.Builder builder()
      Creates a new Builder instance.
      Returns:
      a new Builder instance
      Since:
      1.1.0
    • of

      @SafeVarargs @AsOf("2.1.0") public static <V> EnvironmentAttributeMap of(EnvironmentAttribute<V>... attributes)
      Creates a new WrappedEnvironmentAttributeMap from the given attributes.
      Parameters:
      attributes - the attributes to include
      Returns:
      a new WrappedEnvironmentAttributeMap
      Since:
      2.1.0
    • decode

      @AsOf("3.3.0") public static EnvironmentAttributeMap decode(Object minecraftAttributeMap)
      Reads a Minecraft environment attribute map into a wrapper.
      Parameters:
      minecraftAttributeMap - the attribute map to read
      Returns:
      the wrapper for it
      Since:
      3.3.0
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • pending

      public List<EnvironmentAttributeMap.Pending<?>> pending()
      Returns the value of the pending record component.
      Returns:
      the value of the pending record component