Class PaperItemResources

java.lang.Object
fr.robie.machineengine.api.paper.PaperItemResources
All Implemented Interfaces:
ItemResources.Access

public final class PaperItemResources extends Object implements ItemResources.Access
Resources held by items on Paper (D32): what an item holds comes from its ResourceItem CraftEngine behaviors, the amounts live in its CraftEngine item data under minecraft:custom_data → machineengine.resources.<type>.

Methods that change an ItemStack change the given stack itself, whether it is a server stack (from an inventory) or a plain Bukkit one.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final PaperItemResources
    The ItemResources.Access the engine installs on Paper.
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    add(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource, long amount)
    Adds (or with a negative amount, takes) up to amount, within the capacity.
    long
    amount(@NotNull ResourceVariant item, @NotNull net.kyori.adventure.key.Key resource)
     
    static long
    amount(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource)
     
    static @Nullable ResourceItem
    behavior(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource)
    The behavior of stack that holds resource, or null.
    static @NotNull List<ResourceItem>
    behaviors(@NotNull org.bukkit.inventory.ItemStack stack)
    Every resource stack can hold, in the order of its behaviors.
    long
    capacity(@NotNull ResourceVariant item, @NotNull net.kyori.adventure.key.Key resource)
    How much of resource item holds when full; 0 if it cannot hold it.
    static long
    capacity(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource)
    How much of resource stack holds when full; 0 if it cannot hold it.
    static void
    migratePdcLong(@NotNull String pdcKey, @NotNull Function<net.momirealms.craftengine.core.item.Item, @Nullable net.kyori.adventure.key.Key> resource)
    Converts data an addon kept in Bukkit's persistent data before D32: a long under the persistent data key pdcKey becomes the amount of the resource resource returns for the item (null: drop the value).
    static void
    migratePdcLong(@NotNull String pdcKey, @NotNull net.kyori.adventure.key.Key resource)
     
    static void
    onChange(@NotNull Consumer<org.bukkit.inventory.ItemStack> listener)
    Called with the resulting stack after every amount change, e.g.
    withAmount(@NotNull ResourceVariant item, @NotNull net.kyori.adventure.key.Key resource, long amount)
    The same item holding amount of resource.
    static @NotNull org.bukkit.inventory.ItemStack
    withAmount(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource, long amount)
    Sets the amount of resource in stack, clamped to its capacity; nothing changes if it cannot hold it.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • behavior

      @Nullable public static @Nullable ResourceItem behavior(@NotNull @NotNull org.bukkit.inventory.ItemStack stack, @NotNull @NotNull net.kyori.adventure.key.Key resource)
      The behavior of stack that holds resource, or null.
    • behaviors

      @NotNull public static @NotNull List<ResourceItem> behaviors(@NotNull @NotNull org.bukkit.inventory.ItemStack stack)
      Every resource stack can hold, in the order of its behaviors.
    • capacity

      public static long capacity(@NotNull @NotNull org.bukkit.inventory.ItemStack stack, @NotNull @NotNull net.kyori.adventure.key.Key resource)
      How much of resource stack holds when full; 0 if it cannot hold it.
    • amount

      public static long amount(@NotNull @NotNull org.bukkit.inventory.ItemStack stack, @NotNull @NotNull net.kyori.adventure.key.Key resource)
    • withAmount

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack withAmount(@NotNull @NotNull org.bukkit.inventory.ItemStack stack, @NotNull @NotNull net.kyori.adventure.key.Key resource, long amount)
      Sets the amount of resource in stack, clamped to its capacity; nothing changes if it cannot hold it.
      Returns:
      stack, changed
    • add

      public static long add(@NotNull @NotNull org.bukkit.inventory.ItemStack stack, @NotNull @NotNull net.kyori.adventure.key.Key resource, long amount)
      Adds (or with a negative amount, takes) up to amount, within the capacity.
      Returns:
      the amount actually moved, signed like amount
    • migratePdcLong

      public static void migratePdcLong(@NotNull @NotNull String pdcKey, @NotNull @NotNull Function<net.momirealms.craftengine.core.item.Item, @Nullable net.kyori.adventure.key.Key> resource)
      Converts data an addon kept in Bukkit's persistent data before D32: a long under the persistent data key pdcKey becomes the amount of the resource resource returns for the item (null: drop the value). Runs the first time such an item is read.
    • migratePdcLong

      public static void migratePdcLong(@NotNull @NotNull String pdcKey, @NotNull @NotNull net.kyori.adventure.key.Key resource)
    • onChange

      public static void onChange(@NotNull @NotNull Consumer<org.bukkit.inventory.ItemStack> listener)
      Called with the resulting stack after every amount change, e.g. to update the lore.
    • capacity

      public long capacity(@NotNull @NotNull ResourceVariant item, @NotNull @NotNull net.kyori.adventure.key.Key resource)
      Description copied from interface: ItemResources.Access
      How much of resource item holds when full; 0 if it cannot hold it.
      Specified by:
      capacity in interface ItemResources.Access
    • amount

      public long amount(@NotNull @NotNull ResourceVariant item, @NotNull @NotNull net.kyori.adventure.key.Key resource)
      Specified by:
      amount in interface ItemResources.Access
    • withAmount

      @NotNull public @NotNull ResourceVariant withAmount(@NotNull @NotNull ResourceVariant item, @NotNull @NotNull net.kyori.adventure.key.Key resource, long amount)
      Description copied from interface: ItemResources.Access
      The same item holding amount of resource.
      Specified by:
      withAmount in interface ItemResources.Access