EventsAPI

From FiguraMC
Revision as of 21:30, 9 October 2024 by TheKillerBunny (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Not to be confused with Event.

Events is a global which contains every Event, which are fired when certain things happen. For example, if you want to count ticks, you can use the tick or world tick event.

local tick = 0

-- Register event
function events.TICK()
  tick = tick + 1
end
-- or
events.TICK:register(function()
  tick = tick + 1
end)

Note that not everyone needs to count ticks

Methods

Method Description
getEvents Returns a table of every event

Fields

Event Description
ENTITY_INIT Runs when the player is loaded
TICK Runs every tick the player is rendered
WORLD_TICK Runs every tick the world is rendered
RENDER Runs every frame the player is rendered
POST_RENDER Runs every frame AFTER the player is rendered
WORLD_RENDER Runs every frame the world is rendered
POST_WORLD_RENDER Runs every frame AFTER the world is rendered
SKULL_RENDER Runs every frame for every skull when the skull is rendered.
ARROW_RENDER Runs every frame for every arrow when rendered.
TRIDENT_RENDER Runs every frame for every trident when rendered.
ITEM_RENDER Runs every frame for every item when rendered.
CHAT_SEND_MESSAGE Runs every time the player sends something in chat, including commands. Allows for changing the message
CHAT_RECEIVE_MESSAGE Runs every time the player receives something in chat. Allows for changing the message
MOUSE_SCROLL Runs every time the mouse is scrolled. Allows for cancelling the vanilla function
MOUSE_MOVE Runs every time the mouse is moved. Allows for cancelling the vanilla function
MOUSE_PRESS Runs every time the mouse is clicked. Allows for cancelling the vanilla function
KEY_PRESS Runs every time a key is pressed. Allows for cancelling the vanilla function
CHAR_TYPED Runs every time a character is typed.
USE_ITEM Runs every time an item is used by the player.
ON_PLAY_SOUND Runs every time a sound is played
RESOURCE_RELOAD Runs every time resources are reloaded
TOTEM Runs every time a totem of undying is activated
DAMAGE Runs whenever the player takes damage

Methods

getEvents


Returns a table of every event

-- Example function to clear all events
function clearEvents()
  for _, v in pairs(events:getEvents()) do
    v:clear()
  end
end