Class Node
Each item in the scene graph is called a Node. Branch nodes are of type Parent.
If a program adds a child node to a Parent and that node is already a child of a different Parent or the root of a Scene, the node is automatically (and silently) removed from its former parent.
It is possible to rearrange the scene graph, e.g. to move a node or subtree from one location in the scene graph to another. This is normally done by removing the node from its current location before inserting it at the new location. However, a subtree will be automatically removed if it is added to a new parent, as described above.
Coordinate System
The Node class defines a computer graphics "local" coordinate system. Coordinates are
specified in integer pixels, with the origin (0,0) in the top-left corner of the node.
The x-coordinate increases to the right, and the y-coordinate increases downwards.
Transformations
Translation coordinates are specified in integer pixels, and move the node's origin by the specified amount in the x and y directions. The translation is applied after the layout has been computed, but before the node is rendered.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract intReturns the height of the node.intReturns the x coordinate of the node's origin.intReturns the y coordinate of the node's origin.java.util.function.Consumer<NodeClickContext>Returns the consumer that is called when the node is clicked.java.util.function.Consumer<NodeClickContext>Returns the consumer that is called when the node receives a hot bar click.java.util.function.Consumer<NodeClickContext>Returns the consumer that is called when the node is left-clicked.java.util.function.Consumer<NodeClickContext>Returns the consumer that is called when the node is right-clicked.java.util.function.Consumer<NodeClickContext>Returns the consumer that is called when the node is shift-clicked.Returns the parent of this node.intReturns the x translation of the node.intReturns the y translation of the node.abstract intgetWidth()Returns the width of the node.booleanReturns whether the node is clipping its children.booleanReturns whether the node is visible.abstract NodenodeAt(int x, int y) Returns the node at the given coordinates.abstract org.bukkit.inventory.ItemStackpixelAt(int x, int y) Returns anItemStackrepresenting the pixel at the given coordinates.voidrelocate(int layoutX, int layoutY) Moves the node to the specified location.voidsetClipping(boolean clipping) Sets whether the node is clipping its children.voidsetLayoutX(int layoutX) Sets the x coordinate of the node's origin.voidsetLayoutY(int layoutY) Sets the y coordinate of the node's origin.voidsetOnClick(java.util.function.Consumer<NodeClickContext> onClick) Sets the consumer that is called when the node is clicked.voidsetOnHotBarClick(java.util.function.Consumer<NodeClickContext> onHotBarClick) Sets the consumer that is called when the node receives a hot bar click.voidsetOnLeftClick(java.util.function.Consumer<NodeClickContext> onLeftClick) Sets the consumer that is called when the node is left-clicked.voidsetOnRightClick(java.util.function.Consumer<NodeClickContext> onRightClick) Sets the consumer that is called when the node is right-clicked.voidsetOnShiftClick(java.util.function.Consumer<NodeClickContext> onShiftClick) Sets the consumer that is called when the node is shift-clicked.protected final voidvoidsetTranslateX(int translateX) Sets the x translation of the node.voidsetTranslateY(int translateY) Sets the y translation of the node.voidsetVisible(boolean visible) Sets whether the node is visible.
-
Constructor Details
-
Node
public Node()
-
-
Method Details
-
getParent
Returns the parent of this node. If this node has no parent, this method returns null.- Returns:
- the parent of this node
-
setParent
-
getLayoutX
public int getLayoutX()Returns the x coordinate of the node's origin. The origin is the top-left corner of the node.- Returns:
- the x coordinate of the node's origin
-
setLayoutX
public void setLayoutX(int layoutX) Sets the x coordinate of the node's origin. The origin is the top-left corner of the node.- Parameters:
layoutX- the x coordinate of the node's origin
-
getLayoutY
public int getLayoutY()Returns the y coordinate of the node's origin. The origin is the top-left corner of the node.- Returns:
- the y coordinate of the node's origin
-
setLayoutY
public void setLayoutY(int layoutY) Sets the y coordinate of the node's origin. The origin is the top-left corner of the node.- Parameters:
layoutY- the y coordinate of the node's origin
-
relocate
public void relocate(int layoutX, int layoutY) Moves the node to the specified location. This is equivalent to setting the layoutX and layoutY properties.- Parameters:
layoutX- the x coordinate of the node's originlayoutY- the y coordinate of the node's origin
-
getTranslateX
public int getTranslateX()Returns the x translation of the node. The translation is applied after the layout has been computed, but before the node is rendered.- Returns:
- the x translation of the node
-
setTranslateX
public void setTranslateX(int translateX) Sets the x translation of the node. The translation is applied after the layout has been computed, but before the node is rendered.- Parameters:
translateX- the x translation of the node
-
getTranslateY
public int getTranslateY()Returns the y translation of the node. The translation is applied after the layout has been computed, but before the node is rendered.- Returns:
- the y translation of the node
-
setTranslateY
public void setTranslateY(int translateY) Sets the y translation of the node. The translation is applied after the layout has been computed, but before the node is rendered.- Parameters:
translateY- the y translation of the node
-
getWidth
public abstract int getWidth()Returns the width of the node.- Returns:
- the width of the node
-
getHeight
public abstract int getHeight()Returns the height of the node.- Returns:
- the height of the node
-
isVisible
public boolean isVisible()Returns whether the node is visible. If a node is not visible, it will not be rendered, but it will still be considered for layout calculations.- Returns:
- whether the node is visible
-
setVisible
public void setVisible(boolean visible) Sets whether the node is visible. If a node is not visible, it will not be rendered, but it will still be considered for layout calculations.- Parameters:
visible- whether the node is visible
-
isClipping
public boolean isClipping()Returns whether the node is clipping its children. If a node is clipping its children, children that are outside the bounds of the node will not be rendered.- Returns:
- whether the node is clipping its children
-
setClipping
public void setClipping(boolean clipping) Sets whether the node is clipping its children. If a node is clipping its children, children that are outside the bounds of the node will not be rendered.- Parameters:
clipping- whether the node is clipping its children
-
getOnClick
Returns the consumer that is called when the node is clicked.This consumer will be called when the node is clicked, regardless of the type of click.
- Returns:
- the consumer that is called when the node is clicked
-
setOnClick
Sets the consumer that is called when the node is clicked.This consumer will be called when the node is clicked, regardless of the type of click.
- Parameters:
onClick- the consumer that is called when the node is clicked
-
getOnLeftClick
Returns the consumer that is called when the node is left-clicked.- Returns:
- the consumer that is called when the node is left-clicked
-
setOnLeftClick
Sets the consumer that is called when the node is left-clicked.- Parameters:
onLeftClick- the consumer that is called when the node is left-clicked
-
getOnRightClick
Returns the consumer that is called when the node is right-clicked.- Returns:
- the consumer that is called when the node is right-clicked
-
setOnRightClick
Sets the consumer that is called when the node is right-clicked.- Parameters:
onRightClick- the consumer that is called when the node is right-clicked
-
getOnShiftClick
Returns the consumer that is called when the node is shift-clicked.- Returns:
- the consumer that is called when the node is shift-clicked
-
setOnShiftClick
Sets the consumer that is called when the node is shift-clicked.- Parameters:
onShiftClick- the consumer that is called when the node is shift-clicked
-
getOnHotBarClick
Returns the consumer that is called when the node receives a hot bar click.- Returns:
- the consumer that is called when the node receives a hot bar click
-
setOnHotBarClick
Sets the consumer that is called when the node receives a hot bar click.- Parameters:
onHotBarClick- the consumer that is called when the node receives a hot bar click
-
pixelAt
public abstract org.bukkit.inventory.ItemStack pixelAt(int x, int y) Returns anItemStackrepresenting the pixel at the given coordinates. The coordinates are relative to this parent's bounds.- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- the ItemStack at the given coordinates, or null if there is no pixel at the given coordinates
-
nodeAt
Returns the node at the given coordinates. The coordinates are relative to this parent's bounds.- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- the node at the given coordinates, or null if there is no node at the given coordinates
-