java.lang.Object
com.ultikits.ultitools.abstracts.gui.declarative.core.RenderNode

public class RenderNode extends Object
RenderNode 是虚拟渲染树的节点,代表一个要渲染的槽位。

RenderNode 是框架内部使用的对象,用于:

  • 描述每个槽位应该显示什么(Icon)
  • 记录槽位位置(slotIndex)
  • 支持稳定标识(slotKey)用于 diff
  • 组织成树结构以支持布局计算

注意: RenderNode 不直接操作 Bukkit Inventory, 它只是一个虚拟表示,由 GuiRenderer 转换为实际的 Inventory 操作。

Since:
6.2.0
Version:
1.0.0
Author:
UltiTools Team
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final @NotNull List<RenderNode>
    子节点(用于容器类型)。
    private @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent>
    点击事件处理器。
    private @Nullable mc.obliviate.inventory.Icon
    要在此槽位显示的 Icon。 如果为 null,表示此槽位应该为空。
    private final @Nullable SlotKey
    槽位的唯一标识,用于 diff 算法识别相同节点。 如果为 null,则使用 slotIndex 进行识别。
    private final Map<String,Object>
    节点元数据,用于存储额外信息。
    private @Nullable RenderNode
    父节点。
    private int
    槽位在 Inventory 中的索引(0-based)。 -1 表示尚未分配位置(如容器节点)。 -- GETTER -- 获取槽位索引。 -- SETTER -- 设置槽位索引。
  • Constructor Summary

    Constructors
    Constructor
    Description
    RenderNode(@Nullable SlotKey key, int slotIndex)
    创建一个新的 RenderNode。
    RenderNode(@Nullable SlotKey key, int slotIndex, @Nullable mc.obliviate.inventory.Icon icon)
    创建一个叶子 RenderNode(没有子节点)。
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addChild(@NotNull RenderNode child)
    添加子节点。
    int
    计算子树占用的槽位数量。
    void
    清空所有子节点。
    private void
    collectLeaves(@NotNull RenderNode node, @NotNull List<RenderNode> leaves)
     
    @NotNull RenderNode
    创建此节点的深拷贝(不包括子节点)。
    boolean
     
    @NotNull List<RenderNode>
    获取所有叶子节点的列表(递归)。
    @NotNull List<RenderNode>
    获取子节点列表(不可修改)。
    @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent>
    获取点击处理器。
    @Nullable mc.obliviate.inventory.Icon
    获取图标。
    @Nullable SlotKey
    获取槽位标识。
    @Nullable Object
    getMetadata(@NotNull String key)
    获取元数据。
    @Nullable RenderNode
    获取父节点。
    int
     
    boolean
    检查是否是容器节点(有子节点)。
    boolean
    检查是否是叶子节点(没有子节点)。
    void
    removeChild(@NotNull RenderNode child)
    移除子节点。
    void
    setClickHandler(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> clickHandler)
    设置点击处理器。
    void
    setIcon(@Nullable mc.obliviate.inventory.Icon icon)
    设置图标。
    void
    setMetadata(@NotNull String key, @Nullable Object value)
    设置元数据。
    (package private) void
    setParent(@Nullable RenderNode parent)
    设置父节点。
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • key

      @Nullable private final @Nullable SlotKey key
      槽位的唯一标识,用于 diff 算法识别相同节点。 如果为 null,则使用 slotIndex 进行识别。
    • slotIndex

      private int slotIndex
      槽位在 Inventory 中的索引(0-based)。 -1 表示尚未分配位置(如容器节点)。 -- GETTER -- 获取槽位索引。 -- SETTER -- 设置槽位索引。
    • icon

      @Nullable private @Nullable mc.obliviate.inventory.Icon icon
      要在此槽位显示的 Icon。 如果为 null,表示此槽位应该为空。
    • clickHandler

      @Nullable private @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> clickHandler
      点击事件处理器。
    • parent

      @Nullable private @Nullable RenderNode parent
      父节点。
    • children

      @NotNull private final @NotNull List<RenderNode> children
      子节点(用于容器类型)。
    • metadata

      @NotNull private final Map<String,Object> metadata
      节点元数据,用于存储额外信息。
  • Constructor Details

    • RenderNode

      public RenderNode(@Nullable @Nullable SlotKey key, int slotIndex)
      创建一个新的 RenderNode。
      Parameters:
      key - 槽位标识,可为 null
      slotIndex - 槽位索引
    • RenderNode

      public RenderNode(@Nullable @Nullable SlotKey key, int slotIndex, @Nullable @Nullable mc.obliviate.inventory.Icon icon)
      创建一个叶子 RenderNode(没有子节点)。
      Parameters:
      key - 槽位标识
      slotIndex - 槽位索引
      icon - 图标
  • Method Details

    • getKey

      @Nullable public @Nullable SlotKey getKey()
      获取槽位标识。
      Returns:
      SlotKey,可能为 null
    • getIcon

      @Nullable public @Nullable mc.obliviate.inventory.Icon getIcon()
      获取图标。
      Returns:
      Icon,可能为 null
    • setIcon

      public void setIcon(@Nullable @Nullable mc.obliviate.inventory.Icon icon)
      设置图标。
      Parameters:
      icon - 图标
    • getClickHandler

      @Nullable public @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> getClickHandler()
      获取点击处理器。
      Returns:
      点击处理器,可能为 null
    • setClickHandler

      public void setClickHandler(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> clickHandler)
      设置点击处理器。
      Parameters:
      clickHandler - 点击处理器
    • getParent

      @Nullable public @Nullable RenderNode getParent()
      获取父节点。
      Returns:
      父节点,可能为 null
    • setParent

      void setParent(@Nullable @Nullable RenderNode parent)
      设置父节点。
      Parameters:
      parent - 父节点
    • getChildren

      @NotNull public @NotNull List<RenderNode> getChildren()
      获取子节点列表(不可修改)。
      Returns:
      子节点列表
    • addChild

      public void addChild(@NotNull @NotNull RenderNode child)
      添加子节点。
      Parameters:
      child - 子节点
    • removeChild

      public void removeChild(@NotNull @NotNull RenderNode child)
      移除子节点。
      Parameters:
      child - 子节点
    • clearChildren

      public void clearChildren()
      清空所有子节点。
    • getMetadata

      @Nullable public @Nullable Object getMetadata(@NotNull @NotNull String key)
      获取元数据。
      Parameters:
      key - 键
      Returns:
      值,不存在则返回 null
    • setMetadata

      public void setMetadata(@NotNull @NotNull String key, @Nullable @Nullable Object value)
      设置元数据。
      Parameters:
      key - 键
      value - 值
    • isLeaf

      public boolean isLeaf()
      检查是否是叶子节点(没有子节点)。
      Returns:
      如果是叶子节点则返回 true
    • isContainer

      public boolean isContainer()
      检查是否是容器节点(有子节点)。
      Returns:
      如果是容器节点则返回 true
    • getAllLeaves

      @NotNull public @NotNull List<RenderNode> getAllLeaves()
      获取所有叶子节点的列表(递归)。
      Returns:
      所有叶子节点
    • collectLeaves

      private void collectLeaves(@NotNull @NotNull RenderNode node, @NotNull @NotNull List<RenderNode> leaves)
    • calculateSlotCount

      public int calculateSlotCount()
      计算子树占用的槽位数量。
      Returns:
      槽位数量
    • copy

      @NotNull public @NotNull RenderNode copy()
      创建此节点的深拷贝(不包括子节点)。
      Returns:
      新的 RenderNode
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object