Klasse 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
-
Verschachtelte Klassen - Übersicht
Modifizierer und TypKlasseBeschreibungstatic enum
Attach target used in conjunction with theattachTo()
methods. -
Konstruktorübersicht
KonstruktorBeschreibungCreates a new, empty game object using theDEFAULT
layer.GameObject
(int layer) Creates a new, empty game object using the provided layer. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
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.
-
Konstruktordetails
-
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.- Parameter:
layer
- the layer you want to assign. SeeLayer
-
-
Methodendetails
-
getID
public int getID()Gets the unique ID of this object. Note that this ID is only valid during the session!- Gibt zurück:
- the unique ID of this object.
-
getPluginID
public int getPluginID()Gets the ID of the plugin which created this element.- Gibt zurück:
- the plugin ID.
-
isDisposed
public boolean isDisposed()Gets whether or not this game object is disposed.- Gibt zurück:
- 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.- Parameter:
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.- Gibt zurück:
- true if this element is set to active, false if not.
-
setLayer
public void setLayer(int layer) Sets theLayer
for this game object.- Parameter:
layer
- the layer you want to set.- Siehe auch:
-
getLayer
public int getLayer()Gets the layer that is assigned to this game object.- Gibt zurück:
- the layer.
- Siehe auch:
-
setLocalPosition
Sets the position of this object, relative to its parent. If this object has no parent, this is the world position.- Parameter:
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.- Parameter:
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.- Gibt zurück:
- 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.- Parameter:
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.- Parameter:
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.- Gibt zurück:
- 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.- Parameter:
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.- Parameter:
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.- Gibt zurück:
- 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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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).- Gibt zurück:
- true if the element is attached (via one of the
attachTo()
methdos), false if not.
-
setCollider
Assigns a collider to this game object.- Parameter:
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.- Gibt zurück:
- 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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Gibt zurück:
- 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.- Gibt zurück:
- a new, unmodifiable list containing all child objects.
-
getChildCount
public int getChildCount()Gets the number of attached child objects on this object.- Gibt zurück:
- 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!- Parameter:
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.- Typparameter:
T
- type/class of the attribute.- Parameter:
key
- the name of the attribute.- Gibt zurück:
- 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.- Parameter:
key
- the name of the attribute.- Gibt zurück:
- 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).- Parameter:
key
- the name of the attribute.type
- the type of the attribute- Gibt zurück:
- 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.- Parameter:
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.- Gibt zurück:
- a set containing all keys and attributes.
- Example: Print all keys and their values
-