Skip to content

Ecs

Auto-generated from src/stdlib/ecs.mcrs — do not edit manually.

API


ecs_registry_new v2.0.0

Allocate a blank 16-slot component registry.

redscript
fn ecs_registry_new(): int[]

Returns: A new int[] of length 16 with all slots set to 0

Example

redscript
let reg: int[] = ecs_registry_new()

ecs_register v2.0.0

Mark comp_id as registered in the registry and return the updated registry.

redscript
fn ecs_register(reg: int[], comp_id: int): int[]

Parameters

ParameterDescription
regRegistry array from ecs_registry_new
comp_idComponent type ID in range [0, 15]

Returns: Updated registry array

Example

redscript
reg = ecs_register(reg, ECS_COMP_HEALTH)

ecs_is_registered v2.0.0

Check whether comp_id is registered.

redscript
fn ecs_is_registered(reg: int[], comp_id: int): int

Parameters

ParameterDescription
regRegistry array from ecs_registry_new
comp_idComponent type ID in range [0, 15]

Returns: 1 if registered, 0 otherwise

Example

redscript
if (ecs_is_registered(reg, ECS_COMP_HEALTH) == 1) { }

ecs_health_init v2.0.0

Create a health component state with current_hp = max_hp (full health).

redscript
fn ecs_health_init(entity_score: int, max_hp: int): int[]

Parameters

ParameterDescription
entity_scoreScoreboard score identifying the entity
max_hpMaximum hit points

Returns: New 8-element health component state array

Example

redscript
let hp: int[] = ecs_health_init(42, 100)

ecs_health_get v2.0.0

Return current HP from a health component state.

redscript
fn ecs_health_get(state: int[]): int

Parameters

ParameterDescription
stateHealth component state from ecs_health_init

Returns: Current hit point value

Example

redscript
let hp: int = ecs_health_get(state)

ecs_health_max v2.0.0

Return maximum HP from a health component state.

redscript
fn ecs_health_max(state: int[]): int

Parameters

ParameterDescription
stateHealth component state from ecs_health_init

Returns: Maximum hit point value

Example

redscript
let max: int = ecs_health_max(state)

ecs_health_set v2.0.0

Set current HP (clamped to [0, max]) and return the updated state.

redscript
fn ecs_health_set(state: int[], hp: int): int[]

Parameters

ParameterDescription
stateHealth component state from ecs_health_init
hpNew HP value (clamped to valid range automatically)

Returns: Updated state array

Example

redscript
state = ecs_health_set(state, 50)

ecs_health_damage v2.0.0

Subtract amount from HP (clamped to 0) and return the updated state.

redscript
fn ecs_health_damage(state: int[], amount: int): int[]

Parameters

ParameterDescription
stateHealth component state
amountDamage amount to subtract (positive integer)

Returns: Updated state array

Example

redscript
state = ecs_health_damage(state, 30)

ecs_health_heal v2.0.0

Add amount to HP (clamped to max) and return the updated state.

redscript
fn ecs_health_heal(state: int[], amount: int): int[]

Parameters

ParameterDescription
stateHealth component state
amountHealing amount to add (positive integer)

Returns: Updated state array

Example

redscript
state = ecs_health_heal(state, 20)

ecs_health_is_dead v2.0.0

Return 1 if the entity HP is at or below zero, otherwise 0.

redscript
fn ecs_health_is_dead(state: int[]): int

Parameters

ParameterDescription
stateHealth component state

Returns: 1 if dead, 0 if alive

Example

redscript
if (ecs_health_is_dead(state) == 1) { /* handle death */ }

ecs_health_pct v2.0.0

Return HP as a percentage in fixed-point ×10000 (e.g., 5000 = 50.00%).

redscript
fn ecs_health_pct(state: int[]): int

Parameters

ParameterDescription
stateHealth component state

Returns: current_hp * 10000 / max_hp, or 0 if max_hp is zero

Example

redscript
let pct: int = ecs_health_pct(state)

ecs_vel_init v2.0.0

Create a velocity component state with the given initial velocities.

redscript
fn ecs_vel_init(vx: int, vy: int, vz: int): int[]

Parameters

ParameterDescription
vxX velocity ×1000 fixed-point (1000 = 1.0 block/tick)
vyY velocity ×1000 fixed-point
vzZ velocity ×1000 fixed-point

Returns: New 8-element velocity component state array

Example

redscript
let vel: int[] = ecs_vel_init(1000, 0, 500)

ecs_vel_get_x v2.0.0

Return X velocity from a velocity component state.

redscript
fn ecs_vel_get_x(state: int[]): int

Parameters

ParameterDescription
stateVelocity component state

Returns: X velocity ×1000 fixed-point


ecs_vel_get_y v2.0.0

Return Y velocity from a velocity component state.

redscript
fn ecs_vel_get_y(state: int[]): int

Parameters

ParameterDescription
stateVelocity component state

Returns: Y velocity ×1000 fixed-point


ecs_vel_get_z v2.0.0

Return Z velocity from a velocity component state.

redscript
fn ecs_vel_get_z(state: int[]): int

Parameters

ParameterDescription
stateVelocity component state

Returns: Z velocity ×1000 fixed-point


ecs_vel_set v2.0.0

Set all velocity components and return the updated state.

redscript
fn ecs_vel_set(state: int[], vx: int, vy: int, vz: int): int[]

Parameters

ParameterDescription
stateVelocity component state
vxNew X velocity ×1000
vyNew Y velocity ×1000
vzNew Z velocity ×1000

Returns: Updated state array

Example

redscript
state = ecs_vel_set(state, 500, 1200, 0)

ecs_vel_speed v2.0.0

Return the speed (magnitude) of the velocity vector ×1000.

Uses sqrt_fixed from math.mcrs. For example, ecs_vel_speed([3000, 4000, 0, ...]) returns approximately 5000.

redscript
fn ecs_vel_speed(state: int[]): int

Parameters

ParameterDescription
stateVelocity component state

Returns: sqrt(vx² + vy² + vz²) in ×1000 fixed-point

Example

redscript
let speed: int = ecs_vel_speed(vel_state)

ecs_vel_apply_gravity v2.0.0

Apply gravity by subtracting gravity_fx from the Y velocity each tick.

redscript
fn ecs_vel_apply_gravity(state: int[], gravity_fx: int): int[]

Parameters

ParameterDescription
stateVelocity component state
gravity_fxGravity acceleration ×1000 per tick (e.g. 980 ≈ 0.98 blocks/tick²)

Returns: Updated state array

Example

redscript
vel_state = ecs_vel_apply_gravity(vel_state, 980)

ecs_vel_damp v2.0.0

Apply a friction damping factor to all velocity components.

redscript
fn ecs_vel_damp(state: int[], factor_fx: int): int[]

Parameters

ParameterDescription
stateVelocity component state
factor_fxFriction factor ×10000 (e.g. 8000 = 0.80 damping)

Returns: Updated state array with each component multiplied by factor_fx/10000

Example

redscript
vel_state = ecs_vel_damp(vel_state, 9000)

Released under the MIT License.