Package com.minecolonies.api.inventory
Class InventoryCitizen
java.lang.Object
com.minecolonies.api.inventory.InventoryCitizen
- All Implemented Interfaces:
net.minecraft.world.Nameable,net.neoforged.neoforge.items.IItemHandler,net.neoforged.neoforge.items.IItemHandlerModifiable
public class InventoryCitizen
extends Object
implements net.neoforged.neoforge.items.IItemHandlerModifiable, net.minecraft.world.Nameable
Basic inventory for the citizens.
-
Constructor Summary
ConstructorsConstructorDescriptionInventoryCitizen(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 TypeMethodDescription<T extends net.minecraft.world.entity.LivingEntity>
booleandamageInventoryItem(int slot, int amount, T entityIn, @Nullable Consumer<net.minecraft.world.item.Item> onBroken) Damage an item within the inventorynet.minecraft.world.item.ItemStackextractItem(int slot, int amount, boolean simulate) voidforceArmorStackToSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, net.minecraft.world.item.ItemStack stack) Force an armor stack in a slot.voidforceClearArmorInSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, net.minecraft.world.item.ItemStack stack) Force remove armor stack from a slot.net.minecraft.world.item.ItemStackgetArmorInSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot) Get the armor from a specific equipment slot.@NotNull net.minecraft.network.chat.ComponentGet the formatted TextComponent that will be used for the sender's username in chat.net.minecraft.world.item.ItemStackgetHeldItem(net.minecraft.world.InteractionHand hand) Returns the item that is currently being held by citizen.intgetHeldItemSlot(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.ComponentgetName()Get the name of this object.intgetSlotLimit(int slot) intgetSlots()@NotNull net.minecraft.world.item.ItemStackgetStackInSlot(int index) Returns the stack in the given slot.booleanChecks if the inventory is named.booleanhasSpace()Checks if the inventory has spacenet.minecraft.world.item.ItemStackinsertItem(int slot, net.minecraft.world.item.ItemStack stack, boolean simulate) booleanisEmpty()Checks if the inventory is completely empty.booleanisFull()Checks if the inventory is completely full.booleanisItemValid(int slot, net.minecraft.world.item.ItemStack stack) voidFor 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.voidmoveArmorToInventory(net.minecraft.world.entity.EquipmentSlot equipmentSlot) Move armor from armor slots to inventory.voidread(net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag nbtTagCompound) Reads from the given compound and fills the slots in the inventory with the correct items.voidsetCustomName(String customName) Sets the name of the inventory.voidsetHeldItem(net.minecraft.world.InteractionHand hand, int slot) Set item to be held by citizen.voidsetStackInSlot(int slot, net.minecraft.world.item.ItemStack stack) booleanshrinkInventoryItem(int slot) Shrinks an item in the given slotvoidtransferArmorToSlot(net.minecraft.world.entity.EquipmentSlot equipmentSlot, int slot) Transfer from inventory slot to armor.voidwrite(net.minecraft.core.HolderLookup.Provider provider, 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, waitMethods inherited from interface net.minecraft.world.Nameable
getCustomName
-
Constructor Details
-
InventoryCitizen
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
Creates the inventory of the citizen.- Parameters:
title- Title of the inventory.localeEnabled- Boolean whether the inventory has a custom name.
-
-
Method Details
-
setCustomName
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:
ItemStackcurrently 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:
getSlotsin interfacenet.neoforged.neoforge.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:
getNamein interfacenet.minecraft.world.Nameable- Returns:
- the name of the inventory.
-
hasCustomName
public boolean hasCustomName()Checks if the inventory is named.- Specified by:
hasCustomNamein interfacenet.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:
getStackInSlotin interfacenet.neoforged.neoforge.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<net.minecraft.world.item.Item> onBroken) Damage an item within the inventory- Parameters:
slot- slot to damageamount- damage amountentityIn- entity which uses the itemonBroken- 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:
insertItemin interfacenet.neoforged.neoforge.items.IItemHandler
-
extractItem
@Nonnull public net.minecraft.world.item.ItemStack extractItem(int slot, int amount, boolean simulate) - Specified by:
extractItemin interfacenet.neoforged.neoforge.items.IItemHandler
-
getSlotLimit
public int getSlotLimit(int slot) - Specified by:
getSlotLimitin interfacenet.neoforged.neoforge.items.IItemHandler
-
isItemValid
public boolean isItemValid(int slot, @Nonnull net.minecraft.world.item.ItemStack stack) - Specified by:
isItemValidin interfacenet.neoforged.neoforge.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:
getDisplayNamein interfacenet.minecraft.world.Nameable
-
write
public void write(@NotNull net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag nbtTagCompound) Writes the inventory to nbt.- Parameters:
nbtTagCompound- the compound to store it in.
-
read
public void read(@NotNull net.minecraft.core.HolderLookup.Provider provider, 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:
setStackInSlotin interfacenet.neoforged.neoforge.items.IItemHandlerModifiable
-
getIterableArmorAndHandInv
Get an iterable of armor and hand inventory.- Returns:
- the itemstack iterable.
-