π· Entity API¶
Mobs, dropped items, arrows, minecarts: anything in the world that moves is an "entity". In Pier you find one by its unique id, read its properties and act on it.
Getting an entity object¶
By unique id¶
Rust: Entity::from_id(id)
Go: levilamina.EntityByID(id)
Zig: levilamina.Entity.of(id)
An entity's id usually comes from an event payload: the attackerUid and uid fields of damage and death events.
- Parameters:
- id : integer
the entity's unique id
- id : integer
- Return value: an entity object
- Return type:
Entity- Creating the object does not check that the entity exists; a call after it was removed returns an error. An id can be kept across ticks.
-
Example:
- Rust
Rust - Go
Go - Zig
Zig
Every entity of a dimension¶
Rust: Entity::list(Some(dim))
Go: levilamina.ListActors(dim)
Zig: levilamina.slot("list_actors")
- Parameters:
- dim : integer
the dimension id
- dim : integer
- Return value: entries of entity id and type name
- Return type: Rust
Vec<ActorEntry>, Go([]ActorInfo, error) - Slot:
list_actors -
Example:
- Rust
Rust - Go
Spawning a mob¶
Rust: World::get().spawn_mob(dim, type, x, y, z)
Go: levilamina.SpawnMob(dim, type, x, y, z)
Zig: levilamina.slot("spawn_mob")
- Parameters:
- dim : integer
the dimension id - type : string
the mob type, such asminecraft:zombie - x, y, z : number
the position
- dim : integer
- Return value: the new entity
- Return type: Rust
Result<Entity>, Go(Entity, error) - Slot:
spawn_mob -
Example:
- Rust
Rust - Go
Go - Zig
Entity object: properties¶
Health, type, whether it is on fireβ¦ In Go and Zig every PIER_APROP_* and PIER_ASTR_* of abi.h has a method of its name, such as Health(), IsOnFire(), TypeName() (Zig: health(), isOnFire(), typeName(allocator)); Rust uses entity.num(PIER_APROP_β¦) and entity.text(PIER_ASTR_β¦). A read that fails returns an error. Slots: actor_get_num, actor_get_str.
Entity object: functions¶
zombie stands for the entity object you hold.
Killing an entity¶
Rust: zombie.kill()
Go: zombie.Kill("", 0, 0, 0)
Zig: zombie.kill(allocator, "", 0, 0, 0)
- Return value: nothing on success
- Return type: Rust
Result<()>, Go(string, error) - Slot:
actor_action -
Example:
- Rust
Rust - Go
Go - Zig
Zig
Healing an entity¶
Rust: zombie.heal(amount)
Go: zombie.Heal("", amount, 0, 0)
Zig: zombie.heal(allocator, "", amount, 0, 0)
- Parameters:
- amount : number
how much to heal
- amount : number
- Return value: nothing on success
- Return type: Rust
Result<()>, Go(string, error)- Go and Zig verbs take a string and three numbers; which ones a verb uses is in the comment of its
PIER_AACT_*constant inabi.h.
- Go and Zig verbs take a string and three numbers; which ones a verb uses is in the comment of its
- Slot:
actor_action -
Example:
- Rust
Rust - Go
Go - Zig
Zig
Hurting an entity¶
Rust: zombie.hurt(amount)
Go: zombie.Hurt("", amount, 0, 0)
Zig: zombie.hurt(allocator, "", amount, 0, 0)
- Parameters:
- amount : number
the damage
- amount : number
- Return value: nothing on success
- Return type: Rust
Result<()>, Go(string, error) - Slot:
actor_action -
Example:
- Rust
Rust - Go
Go - Zig
Zig
Teleporting an entity¶
Rust: zombie.teleport_to(dim, x, y, z)
Go: zombie.Teleport(dim, x, y, z)
Zig: zombie.teleport(allocator, dim, x, y, z)
- Parameters:
- dim : integer (text in Go and Zig)
the dimension - x, y, z : number
the position
- dim : integer (text in Go and Zig)
- Return value: nothing on success
- Return type: Rust
Result<()>, Go(string, error) - Slot:
actor_action -
Example:
- Rust
Rust - Go
Go - Zig
Zig
An entity's owner¶
Rust: wolf.owner()
Go: wolf.Owner()
Zig: levilamina.slot("actor_get_owner")
The target and vehicle work the same: Rust target(), vehicle(), Go Target(), Vehicle().
- Return value: the owner's entity object
- Return type: Rust
Result<Option<Entity>>, Go(Entity, error)- In Rust "none" is
Ok(None); in Go, no owner returns an error naming what was read.
- In Rust "none" is
- Slot:
actor_get_owner -
Example:
- Rust
- Go
Go - Zig
An entity's full data¶
Rust: zombie.snapshot()
Go: zombie.Snapshot()
Zig: levilamina.slot("actor_snapshot")
- Return value: all of the entity's NBT: equipment, effects, a custom nameβ¦
- Return type: Rust
Result<NbtValue>, Go(string, error)- A snapshot holds the data of that moment, and does not follow later changes.
- Slot:
actor_snapshot -
Example:
- Rust
- Go