Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

Ecs Patterns

27
archetypes-pattern

Archetypes group entities with the same component signature for cache-efficient iteration. Entities with components [A,B] are stored together, separate from [A,B,C]. This enables fast system processing.

Break Block Listener

EntityEventSystem implementation

Component Iteration

Efficiently iterate over all entities with a specific component using forEachChunk for cache-friendly access.

component-type-pattern

ComponentType<T> provides type-safe access to components. Every component class has a static getComponentType() method that returns its ComponentType for Store operations.

Confirmed Death

Custom EntityStore component

Custom Component

Create custom ECS components with data and clone support.

Custom Component Definition

Define custom ECS components with proper clone support and optional serialization.

ECS Event Handler

Handle ECS events like crafting, block breaking, damage using EntityEventSystem.

ecs-overview

Entity Component System (ECS) architecture overview for Hytale modding. ECS separates data (Components) from logic (Systems), with Entities being just IDs that group components together.

ecs-vs-oop

Understanding why Hytale uses ECS instead of traditional OOP. ECS avoids inheritance problems and enables better performance through data-oriented design.

Entity Creation

Create new entities using Holder blueprint pattern. Collect all components first, then add to store.

entity-ticking-system-pattern

EntityTickingSystem processes entities every tick (frame). It receives an index into an ArchetypeChunk for efficient iteration. Use for per-entity per-frame logic like movement, AI, or HUD updates.

Exploration Component

Custom EntityStore component

Exploration Player Setup System

RefSystem implementation

holder-pattern

Holder<EntityStore> wraps an entity reference with convenient component access methods. Created from ArchetypeChunk index using EntityUtils.toHolder().

Hud System

EntityTickingSystem implementation

Location System

EntityTickingSystem implementation

Lost In Combat

Custom EntityStore component

Marker Component

Create marker components (boolean flags) using singleton pattern for entities without data.

Place Block Listener

EntityEventSystem implementation

Player Game Mode Info

Custom EntityStore component

Player Hud Update System

EntityTickingSystem implementation

Ref Validation

Always validate entity references before use since entities can be deleted at any time.

RefSystem - Entity Lifecycle

React to entity creation and removal events.

store-ref-pattern

The Store<EntityStore> and Ref<EntityStore> pattern is the core way to access entity components in Hytale ECS. Store is your accessor, Ref identifies which entity.

Ticking System

Create systems that run every game tick with query filtering.

universe-world-hierarchy

Hytale world structure: Universe contains multiple Worlds, each World has an EntityStore. The Universe represents the entire game session, Worlds are individual dimensions/areas.