game objects - GregHib/void GitHub Wiki

Game objects make up the entire game world from scenery and rocks on the floor, to castle walls and trees there are over 3.5 million game objects across the world. The majority of objects are inactive and never change, other objects are active and can be interacted with by Players.

Configuration

Objects have one type of config file for storing information ending in .objs.toml

[crashed_star_falling_object]
id = 38659
examine = "It's a crashed star."

[crashed_star_tier_9]
id = 38660
collect_for_next_layer = 15
mining = {
  level = 90,
  ores = [ "stardust" ],
  gems = true
}
examine = "This is a size-9 star."

This information can be obtained using obj.def["examine", ""] see definition extras for more info.

Spawns

Permanent object changes should be added to /data/*.obj-spawns.toml files to be spawned every time the world loads:

spawns = [
  { id = "crate", x = 3081, y = 3488, type = 10, rotation = 1 },
]

Finding Objects

Objects are all stored in the GameObjects map which can be access from scripts with:

class MyContent(
    val objects: GameObjects
) : Script

Or

val objects: GameObjects by inject()

Or in functions with:

val objects: GameObjects = get()

The GameObjects map can be searched by Tile and id, layer or shape:

val tile = Tile(3200, 3200)
val objectsUnder = objects.get(tile) // Get all objects on a tile

val gameObject = objects.get(tile, "large_door_opened") // Get specific object by id

val gameObject = objects.getShape(tile, ObjectShape.WALL_CORNER) // Get specific object by shape

val gameObject = objects.getLayer(tile, ObjectLayer.WALL_DECORATION) // Get specific object by layer

Adding objects

New objects can be spawned with GameObjects add() function allowing scripts to modify the world at any time

// Temporarily add a fire for 60 ticks
val obj = objects.add("fire", tile, shape = ObjectShape.CENTRE_PIECE_STRAIGHT, rotation = 0, ticks = 60)

Warning

Adding a object will override existing objects with the same ObjectLayer.

Removing objects

Objects can also be removed temporarily or permanently

objectOperate("Pick", "wheat") {
    target.remove(30) // Remove the object for 30 ticks
    message("You pick some wheat.")
}

Replacing objects

One object can also be replaced with another temporarily or permanently

objectOperate("Slash", "web*") {
    anim("dagger_slash")
    target.replace("web_slashed", ticks = TimeUnit.MINUTES.toTicks(1)) // Replace the object for 100 ticks
}

Object Data

Due to the shear number of objects in the world they are stored with little information compared to other entities, a game object stores:

Data Description
Id The type of object as a String identifier.
Tile The position of the object as an x, y, level coordinate.
Definition Definition data about this particular type of object.
Shape The type of object, used for layering and interaction path finding.
Rotation A number between 0-3 which represents the direction the object is facing.
⚠️ **GitHub.com Fallback** ⚠️