接口 InventoryView
原文:Represents a view linking two inventories and a single player (whose inventory may or may not be one of the two).
-
嵌套类概要
-
字段概要
-
方法概要
修饰符和类型方法说明void
close()
关闭该窗口视图.int
convertSlot
(int rawSlot) 将原始槽位id转换为本地槽位id (本地槽位id适用于当前正在查看的两个物品栏).int
Check the total number of slots in this view, combining the upper and lower inventories.获取此窗口视图下方的物品栏 (通常是玩家背包).获取玩家客户端鼠标光标所指位置上的物品.getInventory
(int rawSlot) Gets the inventory corresponding to the given raw slot ID.getItem
(int slot) 获取该物品栏指定槽位的物品.Get the original title of this inventory window, before any changes were made usingsetTitle(String)
.获取正查看此窗口的玩家.getSlotType
(int slot) Determine the type of the slot by its raw slot ID.getTitle()
获取物品栏窗口的标题.获取此窗口视图上方的物品栏.getType()
判断该事件中物品栏的类型.void
设置玩家客户端鼠标光标所指位置上的物品.void
设置该物品栏指定槽位的物品.boolean
setProperty
(@NotNull InventoryView.Property prop, int value) Sets an extra property of this inventory if supported by that inventory, for example the state of a progress bar.void
Sets the title of this inventory window to the specified title if the inventory window supports it.
-
字段详细资料
-
OUTSIDE
static final int OUTSIDE- 另请参阅:
-
-
方法详细资料
-
getTopInventory
获取此窗口视图上方的物品栏.原文:Get the upper inventory involved in this transaction.
- 返回:
- 物品栏
-
getBottomInventory
获取此窗口视图下方的物品栏 (通常是玩家背包).原文:Get the lower inventory involved in this transaction.
- 返回:
- 物品栏
-
getPlayer
获取正查看此窗口的玩家.原文:Get the player viewing.
- 返回:
- 玩家
-
getType
判断该事件中物品栏的类型. 这表示将被展示的窗口样式. 该方法永不会返回PLAYER值.原文:Determine the type of inventory involved in the transaction. This indicates the window style being shown. It will never return PLAYER, since that is common to all windows.
- 返回:
- 物品栏类型
-
setItem
设置该物品栏指定槽位的物品.注意: 如果id是 -999, 那么该物品将被扔在地面上. 然而, 这不是必须的行为. (所以你还是通过常规方法扔物品, 毕竟写个-999不看文档的人谁看得懂呢...233).
原文:Sets one item in this inventory view by its raw slot ID.
Note: If slot ID -999 is chosen, it may be expected that the item is dropped on the ground. This is not required behaviour, however.
- 参数:
slot
- 槽位id (可以通过InventoryClickEvent.getRawSlot()获取)item
- 要放置的物品, null则清除
-
getItem
获取该物品栏指定槽位的物品.原文:Gets one item in this inventory view by its raw slot ID.
- 参数:
slot
- 槽位id (可以通过InventoryClickEvent.getRawSlot()获取)- 返回:
- 该槽位内的物品
-
setCursor
设置玩家客户端鼠标光标所指位置上的物品.原文:Sets the item on the cursor of one of the viewing players.
- 参数:
item
- 要放置的物品, null则清除
-
getCursor
获取玩家客户端鼠标光标所指位置上的物品.原文:Get the item on the cursor of one of the viewing players.
- 返回:
- 光标所指物品, 如果所指槽位为空返回null
-
getInventory
Gets the inventory corresponding to the given raw slot ID. If the slot ID isOUTSIDE
null will be returned, otherwise behaviour for illegal and negative slot IDs is undefined. May be used withconvertSlot(int)
to directly index an underlying inventory.- 参数:
rawSlot
- The raw slot ID.- 返回:
- corresponding inventory, or null
-
convertSlot
int convertSlot(int rawSlot) 将原始槽位id转换为本地槽位id (本地槽位id适用于当前正在查看的两个物品栏).若原始槽位id指向窗口的上半部分的物品栏, 那么返回的值不变, 此时返回值适用于getTopInventory().getItem(); 若该id指向底部物品栏, 返回的值将与原始槽位id不同, 此时返回值适用于getBottomInventory().getItem().
这是玩家背包的一个实例(来自代码注释):
原文:Converts a raw slot ID into its local slot ID into whichever of the two inventories the slot points to.
Raw Slots(原始槽位id): 5 1 2 0 6 3 4 7 8 45 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 转换后: 39 1 2 0 38 3 4 37 36 40 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 0 1 2 3 4 5 6 7 8
原文:If the raw slot refers to the upper inventory, it will be returned unchanged and thus be suitable for getTopInventory().getItem(); if it refers to the lower inventory, the output will differ from the input and be suitable for getBottomInventory().getItem().
- 参数:
rawSlot
- 原始槽位id- 返回:
- 转换后的槽位id
-
getSlotType
Determine the type of the slot by its raw slot ID.If the type of the slot is unknown, then
InventoryType.SlotType.CONTAINER
will be returned.- 参数:
slot
- The raw slot ID- 返回:
- the slot type
-
close
void close()关闭该窗口视图.原文:Closes the inventory view.
-
countSlots
int countSlots()Check the total number of slots in this view, combining the upper and lower inventories.Note though that it's possible for this to be greater than the sum of the two inventories if for example some slots are not being used.
- 返回:
- The total size
-
setProperty
Sets an extra property of this inventory if supported by that inventory, for example the state of a progress bar.- 参数:
prop
- the window property to updatevalue
- the new value for the window property- 返回:
- true if the property was updated successfully, false if the property is not supported by that inventory
-
getTitle
获取物品栏窗口的标题.原文:Get the title of this inventory window.
- 返回:
- 标题
-
getOriginalTitle
Get the original title of this inventory window, before any changes were made usingsetTitle(String)
.- 返回:
- the original title
-
setTitle
Sets the title of this inventory window to the specified title if the inventory window supports it.Note if the inventory does not support titles that can be changed (ie, it is not creatable or viewed by a player), then this method will throw an exception.
- 参数:
title
- The new title.
-