Record Class CountItemsInInventoryBonus

java.lang.Object
java.lang.Record
johnsmith.enchantingoverhauled.api.enchantment.theme.power.bonus.CountItemsInInventoryBonus
Record Components:
items - A HolderSet representing the item(s) or item tag that should be counted within the target block entity's inventory.
bonusPerItem - The fixed integer amount of enchanting power added for each matching item counted.
All Implemented Interfaces:
PowerBonus

public record CountItemsInInventoryBonus(net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items, int bonusPerItem) extends Record implements PowerBonus
A data-driven PowerBonus implementation that calculates bonus enchanting power based on the quantity of specific items found inside a power-providing block entity's inventory.

Typically applied to block entities that implement Container, such as Chiseled Bookshelves holding Enchanted Books.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.MapCodec<CountItemsInInventoryBonus>
    The codec responsible for serializing and deserializing instances of this record from JSON.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CountItemsInInventoryBonus(net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items, int bonusPerItem)
    Creates an instance of a CountItemsInInventoryBonus record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the bonusPerItem record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    com.mojang.serialization.MapCodec<? extends PowerBonus>
    Retrieves the MapCodec responsible for encoding and decoding this specific bonus implementation.
    Retrieves the unique identifier string associated with this specific bonus implementation.
    final int
    Returns a hash code value for this object.
    net.minecraft.core.HolderSet<net.minecraft.world.item.Item>
    Returns the value of the items record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • CODEC

      public static final com.mojang.serialization.MapCodec<CountItemsInInventoryBonus> CODEC
      The codec responsible for serializing and deserializing instances of this record from JSON.

      Uses RegistryCodecs.homogeneousList(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<E>>, com.mojang.serialization.Codec<E>) to handle the HolderSet of items.

  • Constructor Details

    • CountItemsInInventoryBonus

      public CountItemsInInventoryBonus(net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items, int bonusPerItem)
      Creates an instance of a CountItemsInInventoryBonus record class.
      Parameters:
      items - the value for the items record component
      bonusPerItem - the value for the bonusPerItem record component
  • Method Details

    • getTypeId

      public String getTypeId()
      Retrieves the unique identifier string associated with this specific bonus implementation.
      Specified by:
      getTypeId in interface PowerBonus
      Returns:
      The constant ID string for this bonus type: "count_items_in_inventory".
    • getCodec

      public com.mojang.serialization.MapCodec<? extends PowerBonus> getCodec()
      Retrieves the MapCodec responsible for encoding and decoding this specific bonus implementation.
      Specified by:
      getCodec in interface PowerBonus
      Returns:
      The MapCodec for this bonus type.
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • items

      public net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items()
      Returns the value of the items record component.
      Returns:
      the value of the items record component
    • bonusPerItem

      public int bonusPerItem()
      Returns the value of the bonusPerItem record component.
      Returns:
      the value of the bonusPerItem record component