Record Class ItemEnchantments

java.lang.Object
java.lang.Record
fr.fidorial.item.component.ItemEnchantments
Record Components:
levels - the level of each enchantment, keyed by enchantment, 1-255

public record ItemEnchantments(Map<TypedKey<EnchantmentDefinition>, Integer> levels) extends Record
The enchantments a stack carries, under minecraft:enchantments, or stores, under minecraft:stored_enchantments.
Since:
0.1.0
See Also:
  • Field Details

    • MAX_LEVEL

      public static final int MAX_LEVEL
      The highest level an enchantment may have on a stack.
      See Also:
    • EMPTY

      public static final ItemEnchantments EMPTY
      No enchantment at all.
  • Constructor Details

  • Method Details

    • level

      public int level(TypedKey<EnchantmentDefinition> enchantment)
      Returns the level of enchantment, 0 when absent.
      Parameters:
      enchantment - the enchantment
      Returns:
      the level of enchantment, 0 when absent
      Since:
      0.1.0
    • has

      public boolean has(TypedKey<EnchantmentDefinition> enchantment)
      Returns whether enchantment is present.
      Parameters:
      enchantment - the enchantment
      Returns:
      whether enchantment is present
      Since:
      0.1.0
    • isEmpty

      public boolean isEmpty()
      Returns whether no enchantment is present.
      Returns:
      whether no enchantment is present
      Since:
      0.1.0
    • with

      public ItemEnchantments with(TypedKey<EnchantmentDefinition> enchantment, int level)
      Returns a copy with enchantment set to level.
      Parameters:
      enchantment - the enchantment
      level - the level, from 1 to 255
      Returns:
      a copy with enchantment set to level
      Throws:
      IllegalArgumentException - if the level is out of range
      Since:
      0.1.0
    • without

      public ItemEnchantments without(TypedKey<EnchantmentDefinition> enchantment)
      Returns a copy without enchantment, or this instance if it is absent.
      Parameters:
      enchantment - the enchantment
      Returns:
      a copy without enchantment, or this instance if it is absent
      Since:
      0.1.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.
    • levels

      Returns the value of the levels record component.
      Returns:
      the value of the levels record component