接口 InventoryView
- 所有已知子接口:
AnvilView,BeaconView,BrewingStandView,CrafterView,EnchantmentView,FurnaceView,LecternView,LoomView,MerchantView,StonecutterView
原文:Represents a view linking two inventories and a single player (whose inventory may or may not be one of the two).
-
嵌套类概要
嵌套类 -
字段概要
字段 -
方法概要
修饰符和类型方法说明voidclose()关闭该窗口视图.intconvertSlot(int rawSlot) 将原始槽位id转换为本地槽位id (本地槽位id适用于当前正在查看的两个物品栏).int检查此视图中的总槽位数, 合并上方和下方物品栏.获取此窗口视图下方的物品栏 (通常是玩家背包).获取玩家客户端鼠标光标所指位置上的物品.getInventory(int rawSlot) 获取与给定原始槽位 ID 对应的物品栏.getItem(int slot) 获取该物品栏指定槽位的物品.获取此物品栏窗口的原始标题 (在使用setTitle(String)进行任何更改之前).获取正查看此窗口的玩家.getSlotType(int slot) 根据原始槽位 ID 确定槽位的类型.getTitle()获取物品栏窗口的标题.获取此窗口视图上方的物品栏.getType()判断该事件中物品栏的类型.void设置玩家客户端鼠标光标所指位置上的物品.void设置该物品栏指定槽位的物品.booleansetProperty(@NotNull InventoryView.Property prop, int value) 设置此物品栏的额外属性 (如果该物品栏支持), 例如进度条的状态.void设置此物品栏窗口的标题 (如果物品栏窗口支持).
-
字段详细资料
-
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
获取与给定原始槽位 ID 对应的物品栏. 如果槽位 ID 是OUTSIDE则返回 null, 否则对于非法和负数槽位 ID 的行为是未定义的. 可与convertSlot(int)一起使用来直接索引底层物品栏.原文:Gets the inventory corresponding to the given raw slot ID. If the slot ID is
OUTSIDEnull 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- 原始槽位 ID- 返回:
- 对应的物品栏, 或 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
根据原始槽位 ID 确定槽位的类型.如果槽位类型未知, 则返回
InventoryType.SlotType.CONTAINER.原文:Determine the type of the slot by its raw slot ID.
If the type of the slot is unknown, then
InventoryType.SlotType.CONTAINERwill be returned.- 参数:
slot- 原始槽位 ID- 返回:
- 槽位类型
-
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.
- 返回:
- 总大小
-
setProperty
设置此物品栏的额外属性 (如果该物品栏支持), 例如进度条的状态.原文:Sets an extra property of this inventory if supported by that inventory, for example the state of a progress bar.
- 参数:
prop- 要更新的窗口属性value- 窗口属性的新值- 返回:
- 如果属性更新成功则返回 true, 如果该物品栏不支持该属性则返回 false
-
getTitle
获取物品栏窗口的标题.原文:Get the title of this inventory window.
- 返回:
- 标题
-
getOriginalTitle
获取此物品栏窗口的原始标题 (在使用setTitle(String)进行任何更改之前).原文:Get the original title of this inventory window, before any changes were made using
setTitle(String).- 返回:
- 原始标题
-
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- 新标题
-
InventoryView及其子类