ScriptInstance

public class ScriptInstance

Represents a running instance of a Lua script bound to a ScriptableEntity.

Manages the Lua VM lifecycle, per-entity state, task ownership, and hook dispatch. The Lua table is lazily instantiated on the first event or query hook call.

Constructors

Link copied to clipboard
public void ScriptInstance(ScriptDefinition definition, ScriptableEntity entity)

Properties

Link copied to clipboard
public LivingEntity currentDirectTarget
Link copied to clipboard
public Event currentEvent
Link copied to clipboard
public LivingEntity currentEventActor
Link copied to clipboard
Link copied to clipboard
public final ScriptableEntity entity

Functions

Link copied to clipboard
public void cancelOwned(int taskId)
Cancel an owned task by id.
Link copied to clipboard
public long getCooldownRemainingTicks(String key)
Link copied to clipboard
public LivingEntity getCurrentDirectTarget()
The direct target of the event being dispatched, or null (e.g.
Link copied to clipboard
public Event getCurrentEvent()
The event currently being dispatched, or null (e.g.
Link copied to clipboard
public LivingEntity getCurrentEventActor()
The actor (e.g.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
public void handleEvent(ScriptHook hook, Event event, LivingEntity directTarget, LivingEntity eventActor)
Invokes the Lua hook function with a lazily-built context table.
Link copied to clipboard
public ScriptQueryResult handleQuery(ScriptHook hook, Event event, LivingEntity directTarget, LivingEntity eventActor)
Invokes a Lua hook synchronously and returns its immutable scalar result.
Link copied to clipboard
public boolean hasOwnedWorkExcept(int hostGuardTask)
Allows a single-input host to release an idle activation without counting its own lifetime guard.
Link copied to clipboard
public void invokeOwnedCallback(String failureContext, LuaFunction callback, Array<LuaValue> args)
Invoke a Lua callback with explicit args under the CPU-time/instruction watchdog.
Link copied to clipboard
public boolean isClosed()
Link copied to clipboard
public boolean isCooldownReady(String key)
Link copied to clipboard
public boolean isPaused()
Link copied to clipboard
public void onTick()
Called each server tick when ON_TICK is supported.
Link copied to clipboard
public void ownCleanup(Runnable cleanup)
Register optional Java-owned restoration.
Link copied to clipboard
public int ownLater(int ticks, Runnable runnable)
Schedule a one-shot owned Java task; auto-cancelled on shutdown.
Link copied to clipboard
public int ownLuaLater(int ticks, LuaFunction callback)
Schedule a one-shot owned Lua callback, invoked with a fresh context table.
Link copied to clipboard
public int ownLuaRepeating(int delayTicks, int intervalTicks, LuaFunction callback)
Schedule a repeating owned Lua callback, each invoked with a fresh context table.
Link copied to clipboard
public int ownRepeating(int delayTicks, int intervalTicks, Runnable runnable)
Schedule a repeating owned Java task; auto-cancelled on shutdown.
Link copied to clipboard
public void setCooldown(String key, long ticks)
Link copied to clipboard
public void setPaused(boolean paused)
Freezes hook and owned-callback execution without discarding the Lua VM or script state.
Link copied to clipboard
public void shutdown()
Shuts down this script instance: cancels all owned tasks, clears state, and notifies the entity.
Link copied to clipboard
public void start()
Eagerly instantiates the Lua VM and registers the per-tick task (if the script declares on_game_tick) WITHOUT firing any hook.