Class GameObject
java.lang.Object
net.risingworld.api.worldelements.GameObject
"Empty" base class for all custom elements. You can still use this class to set up parent/child hierarchies, and you
can also assign colliders to it (which may act as invisible barriers, interaction areas or triggers).
Example: Spawn GameObject and a child
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Attach target used in conjunction with theattachTo()
methods. -
Constructor Summary
ConstructorDescriptionCreates a new, empty game object using theDEFAULT
layer.GameObject
(int layer) Creates a new, empty game object using the provided layer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(GameObject child) void
addComponent
(String component) void
attachTo
(Npc npc, GameObject.AttachTarget target) Attaches the game object to an npc.void
attachTo
(Player player, GameObject.AttachTarget target) Attaches the game object to a player.void
deleteAttribute
(String key) Removes an attribute.<T> T
getAttribute
(String key) Gets the value to which the specified key is mapped, or null if no attribute is stored for that key.Gets a set containing all keys and attributes.int
Gets the number of attached child objects on this object.Gets an unmodifiable list of all children of this object.Gets the collider that was assigned viasetCollider(net.risingworld.api.collider.Collider)
.int
getID()
Gets the unique ID of this object.int
getLayer()
Gets the layer that is assigned to this game object.Gets the local position of this object, relative to its parent.Gets the rotation of this object, relative to its parent.Gets the current local scale of this game object.Gets the current parent UI element, or null if this element has no parent.int
Gets the ID of the plugin which created this element.boolean
hasAttribute
(String key) Gets whether or not the provided attribute exists.boolean
hasAttribute
(String key, Class type) Gets whether or not the provided attribute exists (also checks if it has a specific type).void
invokeComponentMethod
(String component, String method, Object... parameters) boolean
isActive()
Gets whether or not this object is currently active.boolean
Gets whether or not the game object is currently attached to a target (e.g a player or npc etc).boolean
boolean
Gets whether or not this game object is disposed.void
moveToLocalPosition
(float x, float y, float z, float speed) Smoothly moves this object to a target local position.void
moveToLocalPosition
(float x, float y, float z, float speed, Callback<Consumer<Vector3f>> callback) Smoothly moves this object to a target local position.void
moveToLocalPosition
(Vector3f position, float speed) Smoothly moves this object to a target local position.void
moveToLocalPosition
(Vector3f position, float speed, Callback<Consumer<Vector3f>> callback) Smoothly moves this object to a target local position.void
moveToLocalTransform
(Vector3f position, Quaternion rotation, float speed) Smoothly moves and rotates this object to a target local position and rotation.void
readWorldPosition
(Player player, Callback<Vector3f> callback) Reads the actual world position of the game object from a particular player.void
readWorldRotation
(Player player, Callback<Quaternion> callback) Reads the actual world rotation of the game object from a particular player.void
Removes all children from this element.void
removeChild
(GameObject child) Removes a child from this object.void
removeComponent
(String component) void
Removes this object from its parent.void
rotateToLocalRotation
(Quaternion rotation, float speed) Smoothly rotates this object to a target local rotation.void
setActive
(boolean set) Toggles the active state of this object.void
setAttribute
(String key, Object value) Stores an attribute (user data) for the game object.void
setCollider
(Collider collider) Assigns a collider to this game object.void
setColliderVisible
(boolean set) A debug method to visualize the collider of this game object.void
setComponentEnabled
(String component, boolean enabled) void
setComponentProperty
(String component, String property, Object value) Assigns a value to any component property via reflection.void
setLayer
(int layer) Sets theLayer
for this game object.void
setLocalPosition
(float x, float y, float z) Sets the position of this object, relative to its parent.void
setLocalPosition
(Vector3f position) Sets the position of this object, relative to its parent.void
setLocalRotation
(float pitch, float yaw, float roll) Sets the rotation of this object, relative to its parent.void
setLocalRotation
(Quaternion rotation) Sets the rotation of this object, relative to its parent.void
setLocalScale
(float x, float y, float z) Sets the local scale of this object, relative to its parent.void
setLocalScale
(Vector3f scale) Sets the local scale of this object, relative to its parent.
-
Constructor Details
-
GameObject
public GameObject()Creates a new, empty game object using theDEFAULT
layer. -
GameObject
public GameObject(int layer) Creates a new, empty game object using the provided layer.- Parameters:
layer
- the layer you want to assign. SeeLayer
-
-
Method Details
-
getID
public int getID()Gets the unique ID of this object. Note that this ID is only valid during the session!- Returns:
- the unique ID of this object.
-
getPluginID
public int getPluginID()Gets the ID of the plugin which created this element.- Returns:
- the plugin ID.
-
isDisposed
public boolean isDisposed()Gets whether or not this game object is disposed.- Returns:
- true if this game object is disposed, false if not.
-
setActive
public void setActive(boolean set) Toggles the active state of this object. Setting this to false will disable the object in the game scene, i.e it is no longer visible and no longer collides with the player or the world. This automatically affects all child elements as well.
By default, an object is set to active.- Parameters:
set
- true to set the object active, false to disable it.
-
isActive
public boolean isActive()Gets whether or not this object is currently active. Does not check the hierarchy recursively! If the parent of this element is not active, but childs are active, they are treated as non-active elements by the game, but this method would still return true.- Returns:
- true if this element is set to active, false if not.
-
setLayer
public void setLayer(int layer) Sets theLayer
for this game object.- Parameters:
layer
- the layer you want to set.- See Also:
-
getLayer
public int getLayer()Gets the layer that is assigned to this game object.- Returns:
- the layer.
- See Also:
-
setLocalPosition
Sets the position of this object, relative to its parent. If this object has no parent, this is the world position.- Parameters:
position
- a vector which holds the new position coordinates.
-
setLocalPosition
public void setLocalPosition(float x, float y, float z) Sets the position of this object, relative to its parent. If this object has no parent, this is the world position.- Parameters:
x
- the x position (horizontally).y
- the y position (vertically).z
- the z position (horizontally).
-
getLocalPosition
Gets the local position of this object, relative to its parent. If this object has no parent, this is the world position.- Returns:
- the local position, represented as a Vector3f.
-
setLocalRotation
Sets the rotation of this object, relative to its parent. If this object has no parent, this is the world rotation.- Parameters:
rotation
- the quaternion which represents the new rotation.
-
setLocalRotation
public void setLocalRotation(float pitch, float yaw, float roll) Sets the rotation of this object, relative to its parent. If this object has no parent, this is the world rotation.- Parameters:
pitch
- the pitch value (rotation around X axis).yaw
- the yaw value (rotation around Y axis, i.e heading).roll
- the roll value (rotation around Z axis).
-
getLocalRotation
Gets the rotation of this object, relative to its parent. If this object has no parent, this is the world rotation.- Returns:
- a quaternion which represents the current rotation.
-
setLocalScale
Sets the local scale of this object, relative to its parent. If this object has no parent, this is the world scale.- Parameters:
scale
- the new scale along the X, Y and Z axis.
-
setLocalScale
public void setLocalScale(float x, float y, float z) Sets the local scale of this object, relative to its parent. If this object has no parent, this is the world scale.- Parameters:
x
- the scale along the X axis.y
- the scale along the Y axis.z
- the scale along the Z axis.
-
getLocalScale
Gets the current local scale of this game object.- Returns:
- a Vector3f representing the local scale of the object (along the X, Y and Z axis).
-
moveToLocalPosition
Smoothly moves this object to a target local position.- Parameters:
position
- the new target position.speed
- the speed at which the object should move (units/blocks per second, e.g when setting it to 10, the object will move 10 units/blocks per second etc).- Example: Move game object 20 blocks upwards within 5 seconds
-
moveToLocalPosition
public void moveToLocalPosition(float x, float y, float z, float speed) Smoothly moves this object to a target local position.- Parameters:
x
- the target x position (horizontally).y
- the target y position (vertically).z
- the target z position (horizontally).speed
- the speed at which the object should move (units/blocks per second, e.g when setting it to 10, the object will move 10 units/blocks per second etc).
-
moveToLocalPosition
public void moveToLocalPosition(Vector3f position, float speed, Callback<Consumer<Vector3f>> callback) Smoothly moves this object to a target local position.- Parameters:
position
- the new target position.speed
- the speed at which the object should move (units/blocks per second, e.g when setting it to 10, the object will move 10 units/blocks per second etc).callback
- optional callback that gets invoked every tick (while the object is moving). This enables you to provide a new position through the Consumer object (seeConsumer.accept(java.lang.Object)
method).
-
moveToLocalPosition
public void moveToLocalPosition(float x, float y, float z, float speed, Callback<Consumer<Vector3f>> callback) Smoothly moves this object to a target local position.- Parameters:
x
- the target x position (horizontally).y
- the target y position (vertically).z
- the target z position (horizontally).speed
- the speed at which the object should move (units/blocks per second, e.g when setting it to 10, the object will move 10 units/blocks per second etc).callback
- optional callback that gets invoked every tick (while the object is moving). This enables you to provide a new position through the Consumer object (seeConsumer.accept(java.lang.Object)
method).
-
rotateToLocalRotation
Smoothly rotates this object to a target local rotation.- Parameters:
rotation
- the new target rotation.speed
- the speed at which the object should rotate.
-
moveToLocalTransform
Smoothly moves and rotates this object to a target local position and rotation.- Parameters:
position
- the new target position.rotation
- the new target rotation.speed
- the speed at which the object should move and rotate.
-
readWorldPosition
Reads the actual world position of the game object from a particular player. Once the result is available, the callback is invoked (containing the world position of the element as Vector3f).
This method is only useful if this object is attached to a target or child of a parent: in this case, the local position (seegetLocalPosition()
) only returns the local position relative to the parent (or attach target), which makes it difficult to calculate the actual world position, so you can use this method instead to get the correct world position easily. However, if the element is neither attached to a parent nor an attach target, you can usegetLocalPosition()
instead.- Parameters:
player
- the player you want to read the information from. If null, the position is read from the first player this game object is currently linked to. If this game object is not linked with any players yet, an exception is thrown.callback
- callback that is invoked once the result is available from the client.
-
readWorldRotation
Reads the actual world rotation of the game object from a particular player. Once the result is available, the callback is invoked (containing the world rotation of the element as Quaternion).
This method is only useful if this object is attached to a target or child of a parent: in this case, the local rotation (seegetLocalRotation()
) only returns the local rotation relative to the parent (or attach target), which makes it difficult to calculate the final world rotation, so you can use this method instead to get the correct world rotation easily. However, if the element is neither attached to a parent nor an attach target, you can usegetLocalRotation()
instead.- Parameters:
player
- the player you want to read the information from. If null, the rotation is read from the first player this game object is currently linked to. If this game object is not linked with any players yet, an exception is thrown.callback
- callback that is invoked once the result is available from the client.
-
attachTo
Attaches the game object to a player. The game object will then follow the target automatically with no delay. The currently set local position and rotation is kept as offset - so when attaching the element, you may want to update the local position (or set it to 0 0 0) etc.- Parameters:
player
- the player you want to attach this element to.target
- the attach target, i.e where it should be attached to specifically.
-
attachTo
Attaches the game object to an npc.- Parameters:
npc
- the npc you want to attach this element to.target
- the attach target, i.e where it should be attached to specifically.- Example: Attach a plant to an npc head
-
isAttached
public boolean isAttached()Gets whether or not the game object is currently attached to a target (e.g a player or npc etc).- Returns:
- true if the element is attached (via one of the
attachTo()
methdos), false if not.
-
setCollider
Assigns a collider to this game object.- Parameters:
collider
- the new collider. Set to null to remove the collider.- Example: Add a box collider with size 2x2x2 to a game object
-
getCollider
Gets the collider that was assigned viasetCollider(net.risingworld.api.collider.Collider)
. Returns null if no collider was assigned.- Returns:
- the collider assigned to this game object, or null if no collider has been assigned yet.
-
setColliderVisible
public void setColliderVisible(boolean set) A debug method to visualize the collider of this game object. Only works if a collider is assigned.- Parameters:
set
- true to show a debug visualization of this game object, false to hide it.
-
isColliderVisible
public boolean isColliderVisible() -
addComponent
-
removeComponent
-
setComponentEnabled
-
setComponentProperty
Assigns a value to any component property via reflection.- Parameters:
component
- the name/type of the component (e.g "Animator" if you want to access an animator component).property
- the name of the property you want to change.value
- the new value you want to assign.
-
invokeComponentMethod
-
addChild
-
removeChild
Removes a child from this object. It will also be removed from the player world.- Parameters:
child
- the child object you want to remove.
-
removeAllChilds
public void removeAllChilds()Removes all children from this element. They will also be detached from the player UI. -
getParent
Gets the current parent UI element, or null if this element has no parent.- Returns:
- the parent element, or null if no parent is set.
-
removeFromParent
public void removeFromParent()Removes this object from its parent. Same as calling removeChild() on the parent object. -
getChilds
Gets an unmodifiable list of all children of this object.- Returns:
- a new, unmodifiable list containing all child objects.
-
getChildCount
public int getChildCount()Gets the number of attached child objects on this object.- Returns:
- the amount of children this object has. 0 if this object has no child objects.
-
setAttribute
Stores an attribute (user data) for the game object. You can store any type. Note that all attributes will be reset upon server restart!- Parameters:
key
- the name of the attribute.value
- the value/object you want to store. Set null to remove the particular attribute.
-
getAttribute
Gets the value to which the specified key is mapped, or null if no attribute is stored for that key.- Type Parameters:
T
- type/class of the attribute.- Parameters:
key
- the name of the attribute.- Returns:
- the attribute that is stored for that key, or null of the
key does not exists.
- Example:
-
hasAttribute
Gets whether or not the provided attribute exists.- Parameters:
key
- the name of the attribute.- Returns:
- true if the attribute exists, false if not.
-
hasAttribute
Gets whether or not the provided attribute exists (also checks if it has a specific type).- Parameters:
key
- the name of the attribute.type
- the type of the attribute- Returns:
- true if the attribute exists and if it has the desired type, false if not.
- Example: Check if a certain Boolean attribute is stored
-
deleteAttribute
Removes an attribute. Does nothing if the attribute doesn't exist.- Parameters:
key
- the name of the attribute you want to delete.
-
getAttributes
Gets a set containing all keys and attributes.
Be careful when modifying the set, because that affects the attributes.- Returns:
- a set containing all keys and attributes.
- Example: Print all keys and their values
-