Interface VirtualItemHandler
- All Superinterfaces:
ItemHandler
A hook for virtual or proxy items whose behavior cannot be fully expressed by the
ItemStack's visible Material.
Implementations are expected to keep all hot-path methods cheap. They should only inspect compact metadata that was precomputed when the virtual item was created.
Register this handler on a SlimefunItem
via SlimefunItem.addItemHandler(ItemHandler...).
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumA tri-state admission result.static enumA tri-state comparison result.static enumThe context in which a stack is consumed.static enumThe context in which a stack is inserted into an inventory.static final recordA handled value result for operations that replace a stack.static enumThe context in which two stacks are being compared.static enumThe context in which a crafting remainder is resolved. -
Method Summary
Modifier and TypeMethodDescriptionallows(org.bukkit.inventory.ItemStack item, VirtualItemHandler.InventoryContext context) Decide whether a virtual stack may enter an empty slot in a given context.default VirtualItemHandler.ItemResultconsume(org.bukkit.inventory.ItemStack item, int amount, boolean replaceConsumables, VirtualItemHandler.ConsumeContext context) Consume an amount from a stack.default Class<? extends ItemHandler> This method returns the identifier for thisItemHandler.default intgetMaxStackSize(org.bukkit.inventory.ItemStack item, VirtualItemHandler.InventoryContext context, int defaultMaxStackSize) Resolve the effective max stack size for the given stack.default VirtualItemHandler.ItemResultgetRemainder(org.bukkit.inventory.ItemStack item, VirtualItemHandler.RemainderContext context) Resolve the remainder created when a stack is consumed for a crafting operation.default booleanisVirtualItem(org.bukkit.inventory.ItemStack item) This should be a very cheap check that determines whether the given stack belongs to this virtual item system.matches(org.bukkit.inventory.ItemStack left, org.bukkit.inventory.ItemStack right, VirtualItemHandler.MatchContext context) Compare two stacks in a given context.matchesPredicate(org.bukkit.inventory.ItemStack item, Predicate<org.bukkit.inventory.ItemStack> predicate, VirtualItemHandler.MatchContext context) Compare a stack against a recipe predicate.Methods inherited from interface io.github.thebusybiscuit.slimefun4.api.items.ItemHandler
validate
-
Method Details
-
getIdentifier
Description copied from interface:ItemHandlerThis method returns the identifier for thisItemHandler. We use aClassidentifier to group Item Handlers together.- Specified by:
getIdentifierin interfaceItemHandler- Returns:
- The
Classidentifier for thisItemHandler
-
isVirtualItem
default boolean isVirtualItem(@Nullable org.bukkit.inventory.ItemStack item) This should be a very cheap check that determines whether the given stack belongs to this virtual item system.- Parameters:
item- The stack to inspect- Returns:
- Whether this stack should be handled by this hook
-
matches
@Nonnull default VirtualItemHandler.ComparisonResult matches(@Nullable org.bukkit.inventory.ItemStack left, @Nullable org.bukkit.inventory.ItemStack right, @Nonnull VirtualItemHandler.MatchContext context) Compare two stacks in a given context.- Parameters:
left- The left stackright- The right stackcontext- The comparison context- Returns:
- The comparison result
-
matchesPredicate
@Nonnull default VirtualItemHandler.ComparisonResult matchesPredicate(@Nonnull org.bukkit.inventory.ItemStack item, @Nonnull Predicate<org.bukkit.inventory.ItemStack> predicate, @Nonnull VirtualItemHandler.MatchContext context) Compare a stack against a recipe predicate.- Parameters:
item- The stack to inspectpredicate- The target predicatecontext- The comparison context- Returns:
- The comparison result
-
getMaxStackSize
default int getMaxStackSize(@Nonnull org.bukkit.inventory.ItemStack item, @Nonnull VirtualItemHandler.InventoryContext context, int defaultMaxStackSize) Resolve the effective max stack size for the given stack.- Parameters:
item- The stack to inspectcontext- The insertion contextdefaultMaxStackSize- The original max stack size- Returns:
- The effective max stack size
-
allows
@Nonnull default VirtualItemHandler.AdmissionResult allows(@Nonnull org.bukkit.inventory.ItemStack item, @Nonnull VirtualItemHandler.InventoryContext context) Decide whether a virtual stack may enter an empty slot in a given context.- Parameters:
item- The stack to inspectcontext- The insertion context- Returns:
- The admission result
-
consume
@Nonnull default VirtualItemHandler.ItemResult consume(@Nonnull org.bukkit.inventory.ItemStack item, int amount, boolean replaceConsumables, @Nonnull VirtualItemHandler.ConsumeContext context) Consume an amount from a stack.- Parameters:
item- The original stackamount- The amount to consumereplaceConsumables- Whether consumables should be replacedcontext- The consume context- Returns:
- The replacement result
-
getRemainder
@Nonnull default VirtualItemHandler.ItemResult getRemainder(@Nonnull org.bukkit.inventory.ItemStack item, @Nonnull VirtualItemHandler.RemainderContext context) Resolve the remainder created when a stack is consumed for a crafting operation.- Parameters:
item- The consumed stackcontext- The crafting context- Returns:
- The remainder result
-