Class PaperItemResources
java.lang.Object
fr.robie.machineengine.api.paper.PaperItemResources
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionstatic final PaperItemResourcesTheItemResources.Accessthe engine installs on Paper. -
Method Summary
Modifier and TypeMethodDescriptionstatic longadd(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource, long amount) Adds (or with a negativeamount, takes) up toamount, within the capacity.longamount(@NotNull ResourceVariant item, @NotNull net.kyori.adventure.key.Key resource) static longamount(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource) static @Nullable ResourceItembehavior(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource) The behavior ofstackthat holdsresource, ornull.static @NotNull List<ResourceItem> behaviors(@NotNull org.bukkit.inventory.ItemStack stack) Every resourcestackcan hold, in the order of its behaviors.longcapacity(@NotNull ResourceVariant item, @NotNull net.kyori.adventure.key.Key resource) How much ofresourceitemholds when full; 0 if it cannot hold it.static longcapacity(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource) How much ofresourcestackholds when full; 0 if it cannot hold it.static voidmigratePdcLong(@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: alongunder the persistent data keypdcKeybecomes the amount of the resourceresourcereturns for the item (null: drop the value).static voidmigratePdcLong(@NotNull String pdcKey, @NotNull net.kyori.adventure.key.Key resource) static voidCalled with the resulting stack after every amount change, e.g.@NotNull ResourceVariantwithAmount(@NotNull ResourceVariant item, @NotNull net.kyori.adventure.key.Key resource, long amount) The same item holdingamountofresource.static @NotNull org.bukkit.inventory.ItemStackwithAmount(@NotNull org.bukkit.inventory.ItemStack stack, @NotNull net.kyori.adventure.key.Key resource, long amount) Sets the amount ofresourceinstack, clamped to its capacity; nothing changes if it cannot hold it.
-
Field Details
-
ACCESS
TheItemResources.Accessthe engine installs on Paper.
-
-
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 ofstackthat holdsresource, ornull. -
behaviors
@NotNull public static @NotNull List<ResourceItem> behaviors(@NotNull @NotNull org.bukkit.inventory.ItemStack stack) Every resourcestackcan 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 ofresourcestackholds 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 ofresourceinstack, 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 negativeamount, takes) up toamount, 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: alongunder the persistent data keypdcKeybecomes the amount of the resourceresourcereturns 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
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.AccessHow much ofresourceitemholds when full; 0 if it cannot hold it.- Specified by:
capacityin interfaceItemResources.Access
-
amount
public long amount(@NotNull @NotNull ResourceVariant item, @NotNull @NotNull net.kyori.adventure.key.Key resource) - Specified by:
amountin interfaceItemResources.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.AccessThe same item holdingamountofresource.- Specified by:
withAmountin interfaceItemResources.Access
-