Class InventoryCitizen

java.lang.Object
com.minecolonies.api.inventory.InventoryCitizen
All Implemented Interfaces:
net.minecraft.world.Nameable, net.minecraftforge.items.IItemHandler, net.minecraftforge.items.IItemHandlerModifiable

public class InventoryCitizen extends Object implements net.minecraftforge.items.IItemHandlerModifiable, net.minecraft.world.Nameable
Basic inventory for the citizens.
  • Constructor Summary

    Constructors
    Constructor
    Description
    InventoryCitizen(String title, boolean localeEnabled)
    Creates the inventory of the citizen.
    InventoryCitizen(String title, boolean localeEnabled, ICitizenData citizen)
    Creates the inventory of the citizen.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends net.minecraft.world.entity.LivingEntity>
    boolean
    damageInventoryItem(int slot, int amount, T entityIn, @Nullable Consumer<T> onBroken)
    Damage an item within the inventory
    net.minecraft.world.item.ItemStack
    extractItem(int slot, int amount, boolean simulate)
     
    void
    forceArmorStackToSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, net.minecraft.world.item.ItemStack stack)
    Force an armor stack in a slot.
    void
    forceClearArmorInSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, net.minecraft.world.item.ItemStack stack)
    Force remove armor stack from a slot.
    net.minecraft.world.item.ItemStack
    getArmorInSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot)
    Get the armor from a specific equipment slot.
    @NotNull net.minecraft.network.chat.Component
    Get the formatted TextComponent that will be used for the sender's username in chat.
    net.minecraft.world.item.ItemStack
    getHeldItem(net.minecraft.world.InteractionHand hand)
    Returns the item that is currently being held by citizen.
    int
    getHeldItemSlot(net.minecraft.world.InteractionHand hand)
    Gets slot that hold item that is being held by citizen.
    Iterable<net.minecraft.world.item.ItemStack>
    Get an iterable of armor and hand inventory.
    @NotNull net.minecraft.network.chat.Component
    Get the name of this object.
    int
    getSlotLimit(int slot)
     
    int
     
    @NotNull net.minecraft.world.item.ItemStack
    getStackInSlot(int index)
    Returns the stack in the given slot.
    boolean
    Checks if the inventory is named.
    boolean
    Checks if the inventory has space
    net.minecraft.world.item.ItemStack
    insertItem(int slot, net.minecraft.world.item.ItemStack stack, boolean simulate)
     
    boolean
    Checks if the inventory is completely empty.
    boolean
    Checks if the inventory is completely full.
    boolean
    isItemValid(int slot, net.minecraft.world.item.ItemStack stack)
     
    void
    For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it hasn't changed and skip it.
    void
    moveArmorToInventory(net.minecraft.world.entity.EquipmentSlot equipmentSlot)
    Move armor from armor slots to inventory.
    void
    read(net.minecraft.nbt.CompoundTag nbtTagCompound)
    Reads from the given compound and fills the slots in the inventory with the correct items.
    void
    setCustomName(String customName)
    Sets the name of the inventory.
    void
    setHeldItem(net.minecraft.world.InteractionHand hand, int slot)
    Set item to be held by citizen.
    void
    setStackInSlot(int slot, net.minecraft.world.item.ItemStack stack)
     
    boolean
    Shrinks an item in the given slot
    void
    transferArmorToSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, int slot)
    Transfer from inventory slot to armor.
    void
    write(net.minecraft.nbt.CompoundTag nbtTagCompound)
    Writes the inventory to nbt.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface net.minecraft.world.Nameable

    getCustomName
  • Constructor Details

    • InventoryCitizen

      public InventoryCitizen(String title, boolean localeEnabled, ICitizenData citizen)
      Creates the inventory of the citizen.
      Parameters:
      title - Title of the inventory.
      localeEnabled - Boolean whether the inventory has a custom name.
      citizen - Citizen owner of the inventory.
    • InventoryCitizen

      public InventoryCitizen(String title, boolean localeEnabled)
      Creates the inventory of the citizen.
      Parameters:
      title - Title of the inventory.
      localeEnabled - Boolean whether the inventory has a custom name.
  • Method Details

    • setCustomName

      public void setCustomName(String customName)
      Sets the name of the inventory.
      Parameters:
      customName - the string to use to set the name.
    • getHeldItem

      public net.minecraft.world.item.ItemStack getHeldItem(net.minecraft.world.InteractionHand hand)
      Returns the item that is currently being held by citizen.
      Parameters:
      hand - the hand it is held in.
      Returns:
      ItemStack currently being held by citizen.
    • setHeldItem

      public void setHeldItem(net.minecraft.world.InteractionHand hand, int slot)
      Set item to be held by citizen.
      Parameters:
      hand - the hand it is held in.
      slot - Slot index with item to be held by citizen.
    • getHeldItemSlot

      public int getHeldItemSlot(net.minecraft.world.InteractionHand hand)
      Gets slot that hold item that is being held by citizen.
      Parameters:
      hand - the hand it is held in.
      Returns:
      Slot index of held item
    • getSlots

      public int getSlots()
      Specified by:
      getSlots in interface net.minecraftforge.items.IItemHandler
    • hasSpace

      public boolean hasSpace()
      Checks if the inventory has space
      Returns:
      true if the main inventory (without armor slots) has an empty slot.
    • isEmpty

      public boolean isEmpty()
      Checks if the inventory is completely empty.
      Returns:
      true if the main inventory (without armor slots) is completely empty.
    • isFull

      public boolean isFull()
      Checks if the inventory is completely full.
      Returns:
      true if the main inventory (without armor slots) is completely full.
    • getName

      @NotNull public @NotNull net.minecraft.network.chat.Component getName()
      Get the name of this object. For citizens this returns their name.
      Specified by:
      getName in interface net.minecraft.world.Nameable
      Returns:
      the name of the inventory.
    • hasCustomName

      public boolean hasCustomName()
      Checks if the inventory is named.
      Specified by:
      hasCustomName in interface net.minecraft.world.Nameable
      Returns:
      true if the inventory has a custom name.
    • getStackInSlot

      @NotNull public @NotNull net.minecraft.world.item.ItemStack getStackInSlot(int index)
      Returns the stack in the given slot.
      Specified by:
      getStackInSlot in interface net.minecraftforge.items.IItemHandler
      Parameters:
      index - the index.
      Returns:
      the stack.
    • getArmorInSlot

      public net.minecraft.world.item.ItemStack getArmorInSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot)
      Get the armor from a specific equipment slot.
      Parameters:
      equipmentSlot - the slot to get it from.
      Returns:
      the stack.
    • forceArmorStackToSlot

      public void forceArmorStackToSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, net.minecraft.world.item.ItemStack stack)
      Force an armor stack in a slot. This is for container interaction only.
      Parameters:
      equipmentSlot - the slot to pick.
      stack - the stack to set.
    • forceClearArmorInSlot

      public void forceClearArmorInSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, net.minecraft.world.item.ItemStack stack)
      Force remove armor stack from a slot. This is for container interaction only.
      Parameters:
      equipmentSlot - the slot to clear.
      stack - the stack being removed.
    • transferArmorToSlot

      public void transferArmorToSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, int slot)
      Transfer from inventory slot to armor.
      Parameters:
      equipmentSlot - the slot to transfer it to.
      slot - the slot to transfer it from.
    • moveArmorToInventory

      public void moveArmorToInventory(net.minecraft.world.entity.EquipmentSlot equipmentSlot)
      Move armor from armor slots to inventory.
      Parameters:
      equipmentSlot - the origin slot.
    • damageInventoryItem

      public <T extends net.minecraft.world.entity.LivingEntity> boolean damageInventoryItem(int slot, int amount, @Nullable T entityIn, @Nullable @Nullable Consumer<T> onBroken)
      Damage an item within the inventory
      Parameters:
      slot - slot to damage
      amount - damage amount
      entityIn - entity which uses the item
      onBroken - action upon item break
      Returns:
      true if the item broke
    • shrinkInventoryItem

      public boolean shrinkInventoryItem(int slot)
      Shrinks an item in the given slot
      Parameters:
      slot - slot to shrink
      Returns:
      true if item is empty afterwards
    • insertItem

      @Nonnull public net.minecraft.world.item.ItemStack insertItem(int slot, @Nonnull net.minecraft.world.item.ItemStack stack, boolean simulate)
      Specified by:
      insertItem in interface net.minecraftforge.items.IItemHandler
    • extractItem

      @Nonnull public net.minecraft.world.item.ItemStack extractItem(int slot, int amount, boolean simulate)
      Specified by:
      extractItem in interface net.minecraftforge.items.IItemHandler
    • getSlotLimit

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

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

      public void markDirty()
      For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it hasn't changed and skip it.
    • getDisplayName

      @NotNull public @NotNull net.minecraft.network.chat.Component getDisplayName()
      Get the formatted TextComponent that will be used for the sender's username in chat.
      Specified by:
      getDisplayName in interface net.minecraft.world.Nameable
    • write

      public void write(net.minecraft.nbt.CompoundTag nbtTagCompound)
      Writes the inventory to nbt.
      Parameters:
      nbtTagCompound - the compound to store it in.
    • read

      public void read(net.minecraft.nbt.CompoundTag nbtTagCompound)
      Reads from the given compound and fills the slots in the inventory with the correct items.
      Parameters:
      nbtTagCompound - the compound.
    • setStackInSlot

      public void setStackInSlot(int slot, @Nonnull net.minecraft.world.item.ItemStack stack)
      Specified by:
      setStackInSlot in interface net.minecraftforge.items.IItemHandlerModifiable
    • getIterableArmorAndHandInv

      public Iterable<net.minecraft.world.item.ItemStack> getIterableArmorAndHandInv()
      Get an iterable of armor and hand inventory.
      Returns:
      the itemstack iterable.