Entity API

Definition constants

_animations:
A list of tables of the form:
{
    frames = {x=0, y=0},
    speed = 24,
    blend = 0,
    loop = true,
    mesh = "meshname.b3d",
    textures = {"texture.png"},
}

_states:
A list of tables of the form:
{
    animation = "idle",
    step = function(step, dtime, moveresult) end
}
The step function should return nil if the current state should continue,
and should return the name of another state to switch.

_default_state: the initial state

_aom_speed: The speed of the entity

_aom_wander: The number of ticks between each time it wanders

_aom_range: The range it will wander to or track an entity to

_aom_hostile: Mob types that will be used as default second argument to get_target
Use "player" to target players


LuaEntity variables

_animation: The name of the animation that the entity is currently in.

_aom_last_pos: The position the last tick. Used internally for detecting if the entity is stuck and should abort pathfinding

_aom_stuck_timer: The number of ticks that the entity has been stuck for. The path will abort after this reaches 70

_aom_to_pos: The position that the entity is moving towards. Will be nil if the entity is not pathfinding.

_aom_path: A list of vectors which differ by at most sqrt(3) that ends in _aom_to_pos

_aom_path_timer: The amount of ticks since the entity last generated a path. If this is less than 70, the mob will not make a new path

_aom_target: The entity that a hostile entity is currently following.

Functions:

aom_entity_api.do_states()
Does given state code, using _states

aom_entity_api.get_path(self, cost)
Gets a path from current position to self._aom_to_pos using the given cost function

aom_entity_api.do_path(self, speed)
Takes a step along the current self._aom_path

aom_entity_api.get_target(self, targets)
Sets self._aom_to_pos to the position of the nearest mob of a type in targets
use "player" to target players

aom_entity_api.get_wander(self, freq)
Sets self._aom_to_pos to a random position every freq calls

aom_entity_api.min_cost(pos1, pos2)
Get vector distance between the two points

aom_entity_api.min_cost_2d(pos1, pos2)
Get vector distance between the two points, ignoring the y coordinate

aom_entity_api.set_my_animation(self, animation_name, overrides, from_blacklist)
Will set the current animation to the given one is conditions are met.
overrides: A table of overrides to the given entry in _animations
from_blacklist: The animation will not be updated if the name of the current animation is in this list.

aom_entity_api.check_jump(self, strength)
Will try to step up one block if there is one in the way.