public interface Inventory extends java.lang.Iterable<ItemStack>
Material.AIR
的行为时是未指定的.限定符和类型 | 方法和说明 |
---|---|
java.util.HashMap<java.lang.Integer,ItemStack> |
addItem(ItemStack... items)
在物品栏存放所给的物品堆.本方法将尽可能完美地尝试填充已有的但还未达到堆叠上限的物品堆
和空格子.
|
java.util.HashMap<java.lang.Integer,? extends ItemStack> |
all(int materialId)
已过时。
Magic value
|
java.util.HashMap<java.lang.Integer,? extends ItemStack> |
all(ItemStack item)
查找在物品栏内的包含指定物品堆的所有格子与物品堆.只有
物品堆的数目和种类都相同时才会匹配.
|
java.util.HashMap<java.lang.Integer,? extends ItemStack> |
all(Material material)
查找在物品栏内的包含指定物品的所有格子与物品堆.
|
void |
clear()
清除整个物品栏.
|
void |
clear(int index)
清除单个格子.
|
boolean |
contains(int materialId)
已过时。
不安全的参数
|
boolean |
contains(int materialId,
int amount)
已过时。
不安全的参数
|
boolean |
contains(ItemStack item)
检测这个物品栏是否含有与给定的物品堆匹配的物品堆.
|
boolean |
contains(ItemStack item,
int amount)
检测物品栏是否含有一定数量的完全匹配的物品堆.
|
boolean |
contains(Material material)
检测这个物品栏是否含有指定的物品.
|
boolean |
contains(Material material,
int amount)
检查物品栏内是否包含指定的物品,并检查物品堆的数量是否足够(译者自述).
|
boolean |
containsAtLeast(ItemStack item,
int amount)
检测物品栏是否含有与所给物品堆匹配的并数量足够的物品堆.
|
int |
first(int materialId)
已过时。
不安全的参数
|
int |
first(ItemStack item)
查找包含此物品堆的第一个格子。
|
int |
first(Material material)
查找包含此物品的第一个格子.
|
int |
firstEmpty()
返回第一个空格子的格子数.
|
ItemStack[] |
getContents()
返回这个物品栏内的所有物品堆.
|
InventoryHolder |
getHolder()
获得此物品栏的持有者(方块或实体).
|
ItemStack |
getItem(int index)
返回在指定索引的物品堆.
|
Location |
getLocation()
获得对应于此物品栏的方块或实体的位置.
|
int |
getMaxStackSize()
返回这个物品栏的最大物品堆叠数量.
|
java.lang.String |
getName()
返回此物品栏的名字.
|
int |
getSize()
返回此物品栏的大小.
|
ItemStack[] |
getStorageContents()
返回.大部分情况下本方法返回的内容代表整个物品栏,
但某些情况下返回的内容可能不包括盔甲或格子.
|
java.lang.String |
getTitle()
返回此物品栏的标题.
|
InventoryType |
getType()
返回这个物品栏的种类.
|
java.util.List<HumanEntity> |
getViewers()
获得正在查看此物品栏的玩家.
|
java.util.ListIterator<ItemStack> |
iterator() |
java.util.ListIterator<ItemStack> |
iterator(int index)
返回一个从指定索引开始的迭代器.
|
void |
remove(int materialId)
已过时。
不安全的参数
|
void |
remove(ItemStack item)
移除在此物品栏内与给定物品堆匹配的所有物品堆.
|
void |
remove(Material material)
移除在物品栏内与给定物品匹配的所有物品堆.
|
java.util.HashMap<java.lang.Integer,ItemStack> |
removeItem(ItemStack... items)
移除在物品栏内的指定物品堆.
|
void |
setContents(ItemStack[] items)
完全地覆盖物品栏的内容.移除所有存在的内容并替换为指定的物品堆.
|
void |
setItem(int index,
ItemStack item)
在物品栏指定索引存放物品堆.
|
void |
setMaxStackSize(int size)
此方法可以让你改变一个物品栏的最大物品堆叠数量.
|
void |
setStorageContents(ItemStack[] items)
放置所给的物品堆至物品栏.
|
int getSize()
原文:Returns the size of the inventory
int getMaxStackSize()
原文:Returns the maximum stack size for an ItemStack in this inventory.
void setMaxStackSize(int size)
警告:
原文: This method allows you to change the maximum stack size for an inventory.
Caveats:
size
- 最大物品堆叠数量java.lang.String getName()
原文:Returns the name of the inventory
ItemStack getItem(int index)
原文:Returns the ItemStack found in the slot at the given index
index
- 要查找的格子void setItem(int index, ItemStack item)
原文:Stores the ItemStack at the given index of the inventory.
index
- 在哪里存放这个物品堆item
- 要设置的物品堆java.util.HashMap<java.lang.Integer,ItemStack> addItem(ItemStack... items) throws java.lang.IllegalArgumentException
返回的HashMap包含不能存放的物品堆,键是你所给的参数的索引值, 值是你所给的参数指定索引处的物品堆.如果所有物品都被存放,将返回一个空HashMap.
(以下翻译不保证准确性,自己试试呗)如果你传递的物品堆超过了物品的最大堆叠量,首先它们将被按 最大堆叠量[Material.getMaxStackSize()]添加一部分.如果当没有部分的物品堆剩余时, 物品堆将被以Inventory.getMaxStackSize()的数量分割,允许你超过那个物品的最大堆叠量.
已知在一些实现里本方法也将会设置输入的argument amount to the number of that item not placed in slots.
原文:Stores the given ItemStacks in the inventory. This will try to fill existing stacks and empty slots as well as it can.
The returned HashMap contains what it couldn't store, where the key is the index of the parameter, and the value is the ItemStack at that index of the varargs parameter. If all items are stored, it will return an empty HashMap.
If you pass in ItemStacks which exceed the maximum stack size for the Material, first they will be added to partial stacks where Material.getMaxStackSize() is not exceeded, up to Material.getMaxStackSize(). When there are no partial stacks left stacks will be split on Inventory.getMaxStackSize() allowing you to exceed the maximum stack size for that material.
It is known that in some implementations this method will also set the inputted argument amount to the number of that item not placed in slots.
items
- 要存放的物品java.lang.IllegalArgumentException
- 如果items或在内的任何元素为nulljava.util.HashMap<java.lang.Integer,ItemStack> removeItem(ItemStack... items) throws java.lang.IllegalArgumentException
本方法将按照你所给的物品堆的数量和种类作为参数尽可能多地移除物品堆.
返回的HashMap包含不能移除的物品堆,map的键 是你所给的参数的索引值,值是在你所给的参数指定索引处的物品堆.如果 所给的物品堆全部被移除,将返回一个空HashMap.
原文:Removes the given ItemStacks from the inventory.
It will try to remove 'as much as possible' from the types and amounts you give as arguments.
The returned HashMap contains what it couldn't remove, where the key is the index of the parameter, and the value is the ItemStack at that index of the varargs parameter. If all the given ItemStacks are removed, it will return an empty HashMap.
It is known that in some implementations this method will also set the inputted argument amount to the number of that item not removed from slots.
items
- 要移除的物品堆java.lang.IllegalArgumentException
- 如果items为nullItemStack[] getContents()
原文:Returns all ItemStacks from the inventory
void setContents(ItemStack[] items) throws java.lang.IllegalArgumentException
原文:Completely replaces the inventory's contents. Removes all existing contents and replaces it with the ItemStacks given in the array.
items
- 内容的完全替换;数组长度必须小于或等于getSize()
.java.lang.IllegalArgumentException
- 如果数组容量超越了物品栏的容量ItemStack[] getStorageContents()
原文:Return the contents from the section of the inventory where items can
reasonably be expected to be stored. In most cases this will represent
the entire inventory, but in some cases it may exclude armor or result
slots.
It is these contents which will be used for add / contains / remove
methods which look for a specific stack.
void setStorageContents(ItemStack[] items) throws java.lang.IllegalArgumentException
原文:Put the given ItemStacks into the storage slots
items
- 作为物品栏内容的物品堆java.lang.IllegalArgumentException
- 如果数组容量超越了物品栏的容量@Deprecated boolean contains(int materialId)
原文:Checks if the inventory contains any ItemStacks with the given materialId
materialId
- 要检测的物品IDboolean contains(Material material) throws java.lang.IllegalArgumentException
原文:Checks if the inventory contains any ItemStacks with the given material.
material
- 要检测的物品java.lang.IllegalArgumentException
- 如果material为nullboolean contains(ItemStack item)
当物品堆的种类和数量都匹配时才返回true.
原文:Checks if the inventory contains any ItemStacks matching the given ItemStack.
This will only return true if both the type and the amount of the stack match.
item
- 要匹配的物品堆@Deprecated boolean contains(int materialId, int amount)
materialId
- The materialId to check foramount
- The minimum amount to look forboolean contains(Material material, int amount) throws java.lang.IllegalArgumentException
原文:Checks if the inventory contains any ItemStacks with the given material, adding to at least the minimum amount specified.
material
- 要检测的物品amount
- 物品堆数量最小值java.lang.IllegalArgumentException
- 如果material为nullboolean contains(ItemStack item, int amount)
如果物品堆的种类和数量都匹配时才会计数.
原文:Checks if the inventory contains at least the minimum amount specified of exactly matching ItemStacks.
An ItemStack only counts if both the type and the amount of the stack match.
item
- 要匹配的物品amount
- 要检查多少相同的物品堆containsAtLeast(ItemStack, int)
boolean containsAtLeast(ItemStack item, int amount)
原文:Checks if the inventory contains ItemStacks matching the given ItemStack whose amounts sum to at least the minimum amount specified.
item
- 要匹配的物品堆amount
- 物品堆数量最小值@Deprecated java.util.HashMap<java.lang.Integer,? extends ItemStack> all(int materialId)
The HashMap contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack with the given materialId is found, an empty map is returned.
materialId
- The materialId to look forjava.util.HashMap<java.lang.Integer,? extends ItemStack> all(Material material) throws java.lang.IllegalArgumentException
返回的HashMap的键是格子的索引,值是在那个格子的物品堆.如果 没有找到指定的物品,将返回一个空map.
原文:Returns a HashMap with all slots and ItemStacks in the inventory with the given Material.
The HashMap contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack with the given Material is found, an empty map is returned.
material
- 要查找的物品java.lang.IllegalArgumentException
- 如果material为nulljava.util.HashMap<java.lang.Integer,? extends ItemStack> all(ItemStack item)
返回的HashMap的键是格子的索引,值是在那个格子的物品堆.如果 没有找到指定的物品堆,将返回一个空map.
原文:Finds all slots in the inventory containing any ItemStacks with the given ItemStack. This will only match slots if both the type and the amount of the stack match
The HashMap contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack with the given Material is found, an empty map is returned.
item
- 要查找的物品堆@Deprecated int first(int materialId)
原文:Finds the first slot in the inventory containing an ItemStack with the given materialId.
materialId
- 要查找的物品的IDint first(Material material) throws java.lang.IllegalArgumentException
原文:Finds the first slot in the inventory containing an ItemStack with the given material
material
- 要查找的物品java.lang.IllegalArgumentException
- 如果material为nullint first(ItemStack item)
原文:Returns the first slot in the inventory containing an ItemStack with the given stack. This will only match a slot if both the type and the amount of the stack match
item
- 要匹配的物品堆int firstEmpty()
原文: Returns the first empty Slot.
@Deprecated void remove(int materialId)
materialId
- The material to removevoid remove(Material material) throws java.lang.IllegalArgumentException
原文:Removes all stacks in the inventory matching the given material.
material
- 要移除的物品java.lang.IllegalArgumentException
- 若material为nullvoid remove(ItemStack item)
只有物品堆的种类和数目相应匹配时对应的格子才会被匹配.
原文:Removes all stacks in the inventory matching the given stack.
This will only match a slot if both the type and the amount of the stack match
item
- 想要移除的物品堆void clear(int index)
原文:Clears out a particular slot in the index.
index
- 格子索引void clear()
原文:Clears out the whole Inventory.
java.util.List<HumanEntity> getViewers()
原文:Gets a list of players viewing the inventory. Note that a player is considered to be viewing their own inventory and internal crafting screen even when said inventory is not open. They will normally be considered to be viewing their inventory even when they have a different inventory screen open, but it's possible for customized inventory screens to exclude the viewer's inventory, so this should never be assumed to be non-empty.
java.lang.String getTitle()
原文:Returns the title of this inventory.
InventoryType getType()
原文:Returns what type of inventory this is.
InventoryHolder getHolder()
原文:Gets the block or entity belonging to the open inventory
java.util.ListIterator<ItemStack> iterator()
iterator
在接口中 java.lang.Iterable<ItemStack>
java.util.ListIterator<ItemStack> iterator(int index)
原文:Returns an iterator starting at the given index. If the index is positive, then the first call to next() will return the item at that index; if it is negative, the first call to previous will return the item at index (getSize() + index).
index
- 索引值Location getLocation()
原文:Get the location of the block or entity which corresponds to this inventory. May return null if this container was custom created or is a virtual / subcontainer.