Code Patterns
Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.
All
225
Command
60
Damage
2
Ecs
27
Entity
5
Gui
75
Interaction
2
Inventory
4
Moderation
3
Permission
2
Player
9
Plugin
4
Storage
2
Teleport
3
Ui
22
Util
5
← Back to Patterns
java
ecs
ecs-vs-oop
Understanding why Hytale uses ECS instead of traditional OOP. ECS avoids inheritance problems and enables better performance through data-oriented design.
Example Code
// WHY ECS OVER OOP?
// PROBLEM 1: Deep Inheritance Hierarchies
// OOP approach:
// Entity
// |-- LivingEntity
// |-- Creature
// |-- Monster
// |-- ZombieBase
// |-- FastZombie
// Adding a "flying" ability requires modifying the hierarchy!
// PROBLEM 2: Diamond Problem
// What if FastZombie needs to be both Flying AND Swimming?
// Multiple inheritance causes conflicts
// PROBLEM 3: Class Explosion
// enemy_types * abilities * states = thousands of classes
// 10 enemies * 5 abilities * 3 states = 150 classes!
// ECS SOLUTION:
// Entities are just IDs
// Components are pure data
// Systems contain logic
// FastZombie in ECS:
// Entity #1234 has components:
// - PositionComponent
// - HealthComponent
// - AIComponent(type: aggressive)
// - SpeedComponent(multiplier: 2.0)
// - ZombieAppearanceComponent
// Adding flying? Just add a component:
store.addComponent(zombieRef, FlyingComponent.getComponentType(), new FlyingComponent());
// The MovementSystem checks for FlyingComponent and handles it
// No class changes needed!
// PERFORMANCE BENEFITS:
// - Components are stored contiguously in memory (cache-friendly)
// - Systems process batches of similar entities efficiently
// - Archetypes enable O(1) queries for entity types
Common Mistakes
Thinking in OOP terms when designing components. Components should be pure data, not have methods with logic.