Class SingleItemSlot

java.lang.Object
alexiil.mc.lib.attributes.item.SingleItemSlotView
alexiil.mc.lib.attributes.item.SingleItemSlot
All Implemented Interfaces:
ItemExtractable, ItemInsertable, ItemTransferable, LimitedConsumer<net.minecraft.item.ItemStack>, Reference<net.minecraft.item.ItemStack>, StackReference
Direct Known Subclasses:
SingleCopyingItemSlot

public class SingleItemSlot extends SingleItemSlotView implements ItemTransferable, StackReference
A delegating accessor of a single slot in a FixedItemInv.
  • Method Details

    • getBackingInv

      public FixedItemInv getBackingInv()
      Overrides:
      getBackingInv in class SingleItemSlotView
    • set

      public final boolean set(net.minecraft.item.ItemStack to, Simulation simulation)
      Sets the stack in this slot to the given stack.
      Specified by:
      set in interface Reference<net.minecraft.item.ItemStack>
      Returns:
      True if the modification was allowed, false otherwise. (For example if the given stack doesn't pass the FixedItemInvView.isItemValidForSlot(int, ItemStack) test).
    • forceSet

      public final void forceSet(net.minecraft.item.ItemStack to)
      Sets the stack in the given slot to the given stack, or throws an exception if it was not permitted.
    • modify

      public final void modify(Function<net.minecraft.item.ItemStack,net.minecraft.item.ItemStack> function)
      Applies the given function to the stack held in the slot, and uses forceSet(ItemStack) on the result (Which will throw an exception if the returned stack is not valid for this inventory).
    • attemptExtraction

      public final net.minecraft.item.ItemStack attemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation)
      Description copied from interface: ItemExtractable
      Attempt to extract *any* ItemStack from this that matches the given ItemFilter.
      Specified by:
      attemptExtraction in interface ItemExtractable
      maxAmount - The maximum number of items that can be extracted. Negative numbers throw an exception.
      simulation - If Simulation.SIMULATE then this should return the same result that a call with Simulation.ACTION would do, but without modifying anything else.
      Returns:
      A new, independent ItemStack that was extracted.
    • attemptInsertion

      public final net.minecraft.item.ItemStack attemptInsertion(net.minecraft.item.ItemStack stack, Simulation simulation)
      Description copied from interface: ItemInsertable
      Inserts the given stack into this insertable, and returns the excess.
      Specified by:
      attemptInsertion in interface ItemInsertable
      Parameters:
      stack - The incoming stack. Must not be modified by this call.
      simulation - If Simulation.SIMULATE then this shouldn't modify anything.
      Returns:
      the excess ItemStack that wasn't accepted. This will be independent of this insertable, however it might be the given stack instead of a completely new object.
    • getInsertionFilter

      public final ItemFilter getInsertionFilter()
      Description copied from interface: ItemInsertable
      Returns an ItemFilter to determine if ItemInsertable.attemptInsertion(ItemStack, Simulation) will accept a stack. The default implementation is a call to attemptInsertion(stack, Simulation.SIMULATE), and it is only useful to override this if the resulting filter contains information that might be usable by the caller.
      Specified by:
      getInsertionFilter in interface ItemInsertable
      Returns:
      A filter to determine if ItemInsertable.attemptInsertion(ItemStack, Simulation) will accept the entirety of a given stack.
    • set

      public boolean set(net.minecraft.item.ItemStack value)
      Specified by:
      set in interface Reference<net.minecraft.item.ItemStack>
      Returns:
      True if the new value was accepted, false otherwise.