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
holder-pattern
Holder<EntityStore> wraps an entity reference with convenient component access methods. Created from ArchetypeChunk index using EntityUtils.toHolder().
Example Code
import com.hypixel.hytale.component.Holder;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.server.core.entity.EntityUtils;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
// In an EntityTickingSystem:
@Override
public void processTick(float deltaTime, int index,
ArchetypeChunk<EntityStore> archetypeChunk,
Store<EntityStore> store,
CommandBuffer<EntityStore> commandBuffer) {
// Convert index to Holder for convenient access
Holder<EntityStore> holder = EntityUtils.toHolder(index, archetypeChunk);
// Get components directly from holder
Player player = holder.getComponent(Player.getComponentType());
PlayerRef playerRef = holder.getComponent(PlayerRef.getComponentType());
if (player == null || playerRef == null) return;
// To get the Ref for store operations, use archetypeChunk:
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(index);
// Now you can use store.addComponent(ref, ...) etc.
}
// Holder provides:
// - getComponent(ComponentType<T>) - Get a component
// - hasComponent(ComponentType<T>) - Check if component exists
// NOTE: Holder does NOT have getRef()!
// Use archetypeChunk.getReferenceTo(index) to get the Ref
Thread Safety
Holder is only valid within the current tick context.
Common Mistakes
Calling holder.getRef() which does not exist. Use archetypeChunk.getReferenceTo(index) instead.