Class CombinedItemHandler

java.lang.Object
com.minecolonies.api.inventory.api.CombinedItemHandler
All Implemented Interfaces:
IWorldNameableModifiable, net.minecraft.world.Nameable, net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>, net.neoforged.neoforge.items.IItemHandler, net.neoforged.neoforge.items.IItemHandlerModifiable

public class CombinedItemHandler extends Object implements net.neoforged.neoforge.items.IItemHandlerModifiable, net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>, IWorldNameableModifiable
Abstract class wrapping around multiple IItemHandler.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CombinedItemHandler(@NotNull String defaultName, @NotNull String customName, @NotNull net.neoforged.neoforge.items.IItemHandlerModifiable... handlers)
    Method to create a new combined CombinedItemHandler with a given custom name.
    CombinedItemHandler(@NotNull String defaultName, @NotNull net.neoforged.neoforge.items.IItemHandlerModifiable... handlers)
    Method to create a new CombinedItemHandler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    deserializeNBT(net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag nbt)
     
    boolean
     
    @NotNull net.minecraft.world.item.ItemStack
    extractItem(int slot, int amount, boolean simulate)
    Extracts an ItemStack from the given slot.
    protected net.neoforged.neoforge.items.IItemHandlerModifiable[]
     
    int
    getLastIndex(int slot)
    Get last index of the current itemHandler a slot belongs to.
    @NotNull net.minecraft.network.chat.Component
     
    int
    getSlotLimit(int slot)
     
    int
    Returns the number of slots available.
    @NotNull net.minecraft.world.item.ItemStack
    getStackInSlot(int slot)
    Returns the ItemStack in a given slot.
    int
     
    @NotNull net.minecraft.world.item.ItemStack
    insertItem(int slot, @NotNull net.minecraft.world.item.ItemStack stack, boolean simulate)
    Inserts an ItemStack into the given slot and return the remainder.
    boolean
    isItemValid(int slot, net.minecraft.world.item.ItemStack stack)
     
    net.minecraft.nbt.CompoundTag
    serializeNBT(net.minecraft.core.HolderLookup.Provider provider)
     
    void
    setName(@Nullable String name)
    Method to set the name of this Nameable.
    void
    setStackInSlot(int slot, net.minecraft.world.item.ItemStack stack)
    Overrides the stack in the given slot.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.minecraft.world.Nameable

    getCustomName, getDisplayName, hasCustomName
  • Constructor Details

    • CombinedItemHandler

      public CombinedItemHandler(@NotNull @NotNull String defaultName, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandlerModifiable... handlers)
      Method to create a new CombinedItemHandler.
      Parameters:
      defaultName - The default name of this CombinedItemHandler.
      handlers - The combining IItemHandlerModifiable.
    • CombinedItemHandler

      public CombinedItemHandler(@NotNull @NotNull String defaultName, @NotNull @NotNull String customName, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandlerModifiable... handlers)
      Method to create a new combined CombinedItemHandler with a given custom name.
      Parameters:
      defaultName - The name of this CombinedItemHandler.
      customName - The preset custom name of this CombinedItemHandler.
      handlers - The combinging IItemHandlerModifiable.
  • Method Details

    • serializeNBT

      public net.minecraft.nbt.CompoundTag serializeNBT(@NotNull net.minecraft.core.HolderLookup.Provider provider)
      Specified by:
      serializeNBT in interface net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
    • deserializeNBT

      public void deserializeNBT(@NotNull net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag nbt)
      Specified by:
      deserializeNBT in interface net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
    • setStackInSlot

      public void setStackInSlot(int slot, net.minecraft.world.item.ItemStack stack)
      Overrides the stack in the given slot. This method is used by the standard Forge helper methods and classes. It is not intended for general use by other mods, and the handler may throw an error if it is called unexpectedly.
      Specified by:
      setStackInSlot in interface net.neoforged.neoforge.items.IItemHandlerModifiable
      Parameters:
      slot - Slot to modify
      stack - ItemStack to set slot to (may be null)
      Throws:
      RuntimeException - if the handler is called in a way that the handler was not expecting.
    • getLastIndex

      public int getLastIndex(int slot)
      Get last index of the current itemHandler a slot belongs to.
      Parameters:
      slot - the slot of an itemHandler.
      Returns:
      the last index.
    • getSlots

      public int getSlots()
      Returns the number of slots available.
      Specified by:
      getSlots in interface net.neoforged.neoforge.items.IItemHandler
      Returns:
      The number of slots available
    • getStackInSlot

      @NotNull public @NotNull net.minecraft.world.item.ItemStack getStackInSlot(int slot)
      Returns the ItemStack in a given slot.

      The result's stack size may be greater than the itemstacks max size.

      If the result is null, then the slot is empty. If the result is not null but the stack size is zero, then it represents an empty slot that will only accept* a specific itemstack.

      IMPORTANT: This ItemStack MUST NOT be modified. This method is not for altering an inventories contents. Any implementers who are able to detect modification through this method should throw an exception.

      SERIOUSLY: DO NOT MODIFY THE RETURNED ITEMSTACK

      Specified by:
      getStackInSlot in interface net.neoforged.neoforge.items.IItemHandler
      Parameters:
      slot - Slot to query
      Returns:
      ItemStack in given slot. May be null.
    • insertItem

      @NotNull public @NotNull net.minecraft.world.item.ItemStack insertItem(int slot, @NotNull @NotNull net.minecraft.world.item.ItemStack stack, boolean simulate)
      Inserts an ItemStack into the given slot and return the remainder. The ItemStack should not be modified in this function! Note: This behaviour is subtly different from IFluidHandlers.fill()
      Specified by:
      insertItem in interface net.neoforged.neoforge.items.IItemHandler
      Parameters:
      slot - Slot to insert into.
      stack - ItemStack to insert.
      simulate - If true, the insertion is only simulated
      Returns:
      The remaining ItemStack that was not inserted (if the entire stack is accepted, then return null). May be the same as the input ItemStack if unchanged, otherwise a new ItemStack.
    • extractItem

      @NotNull public @NotNull net.minecraft.world.item.ItemStack extractItem(int slot, int amount, boolean simulate)
      Extracts an ItemStack from the given slot. The returned value must be null if nothing is extracted, otherwise it's stack size must not be greater than amount or the itemstacks getMaxStackSize().
      Specified by:
      extractItem in interface net.neoforged.neoforge.items.IItemHandler
      Parameters:
      slot - Slot to extract from.
      amount - Amount to extract (may be greater than the current stacks max limit)
      simulate - If true, the extraction is only simulated
      Returns:
      ItemStack extracted from the slot, must be null, if nothing can be extracted
    • getSlotLimit

      public int getSlotLimit(int slot)
      Specified by:
      getSlotLimit in interface net.neoforged.neoforge.items.IItemHandler
    • isItemValid

      public boolean isItemValid(int slot, @Nonnull net.minecraft.world.item.ItemStack stack)
      Specified by:
      isItemValid in interface net.neoforged.neoforge.items.IItemHandler
    • getHandlers

      protected net.neoforged.neoforge.items.IItemHandlerModifiable[] getHandlers()
    • setName

      public void setName(@Nullable @Nullable String name)
      Description copied from interface: IWorldNameableModifiable
      Method to set the name of this Nameable.
      Specified by:
      setName in interface IWorldNameableModifiable
      Parameters:
      name - The new name of this Nameable, or null to reset it to its default.
    • getName

      @NotNull public @NotNull net.minecraft.network.chat.Component getName()
      Specified by:
      getName in interface net.minecraft.world.Nameable
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object