Moonstorm Glass
Based on game build 714014 | Last updated: 2026-03-06
Overview
moonstorm_glass is a prefabricated entity representing a volatile, moon-infused glass structure that acts as an environmental hazard or boss-adjacent object. It is designed to detonate automatically after a 20-second countdown (configurable via TIME) or when fully worked (mined), causing area-of-effect damage to nearby valid entities within a 4-unit radius. The detonation triggers visual and audio FX, removes the entity, and drops loot from a custom table (moonstorm_glass_infused). A secondary, lightweight moonstorm_glass_nub entity serves as a workable handle tied to the main structure.
The component uses the workable, lootdropper, timer, inspectable, named, and updatelooper components to manage state, serialization, and gameplay behavior.
Usage example
-- Example: Spawn and configure moonstorm glass manually (not typical; usually spawned via worldgen or event)
local glass = SpawnPrefab("moonstorm_glass")
glass.Transform:SetPosition(position)
glass.spawnin(glass) -- triggers spawn animation
-- The structure auto-detonates after 20 seconds unless mined first.
-- Mining progress is handled by the workable component and nub.
Dependencies & tags
Components used:
named— sets display name and persists author info.lootdropper— manages loot drops on destruction.workable— enables mining interaction.inspectable— provides status text (e.g.,INFUSED).timer— handles countdown and detonation.updatelooper— updates animations based on remaining time.
Tags added: moonglass, moonstorm_glass (nub only)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
defused | boolean | false | Whether the glass has been successfully mined instead of exploding. Set to true only upon work completion. |
nub | Entity | nil | Reference to the attached moonstorm_glass_nub entity. Used to delegate work to the glass. |
showCloudFXwhenRemoved | boolean | nil (not used in code) | Placeholder for optional FX — not referenced in current implementation. |
Main functions
explode(inst)
- Description: Triggers the detonation sequence: plays crack animation, spawns ground/FX prefabs, plays break sound, applies area-of-effect combat damage to nearby entities, and removes the entity.
- Parameters:
inst(Entity) — the moonstorm glass instance. - Returns: Nothing.
- Error states: Does not validate
instbefore use; assumesinstis valid. Does not detonate ifanimoverevent is never received.
OnWork(inst, worker, workleft)
- Description: Callback invoked after each work increment on the glass. Delegates work to the nub, and if
workleft <= 0, spawns debris FX, drops loot, and removes the entity. - Parameters:
inst(Entity) — the moonstorm glass instance.
worker(Entity) — the entity performing the work.
workleft(number) — remaining work required (decremented each call). - Returns: Nothing.
setanim(inst, workleft)
- Description: (Helper) Selects and plays a center animation (
centre_idle1,centre_idle2,centre_idle3) based on how much work remains relative toTUNING.ROCKS_MINE. - Parameters:
inst(Entity) — the moonstorm glass_nub instance.
workleft(number) — current remaining work. - Returns: Nothing.
ontimedone(inst, data)
- Description: Event handler triggered when the
defusetimetimer completes. Callsexplode(inst)to detonate the glass. - Parameters:
inst(Entity) — the moonstorm glass instance.
data(table) — timer event data containingname. - Returns: Nothing.
getstatus(inst)
- Description: Provides status text for the
inspectablecomponent. - Parameters:
inst(Entity) — the moonstorm glass instance. - Returns:
"INFUSED"if not defused;nilif defused (i.e., mined instead of exploded).
on_save(inst, data)
- Description: Serialization hook; saves the
defusedstate for persistence across reloads. - Parameters:
inst(Entity) — the moonstorm glass instance.
data(table) — the save data table to populate. - Returns: Nothing.
on_load(inst, data)
- Description: Deserialization hook; if
defusedistruein saved data, immediately triggersexplode(inst)and stops the timer. - Parameters:
inst(Entity) — the moonstorm glass instance.
data(table) — the saved data table. - Returns: Nothing.
Events & listeners
- Listens to:
timerdone— triggers detonation whendefusetimeexpires.animover— finalizes explosion after crack animation completes (insideexplode).onremove— ensuresmoonstorm_glass_nubis removed when the main glass is removed.
- Pushes: None directly (relies on engine events like
entity_droplootvialootdropper).