ArchetypeChunk
Package: com.hypixel.hytale.component
public class ArchetypeChunk<ECS_TYPE>Columnar storage for entities that share the same Archetype. Components are stored in parallel arrays indexed by entity position within the chunk, enabling cache-friendly iteration. Each chunk holds a Ref array and a 2D component array (Component[componentTypeIndex][entityIndex]).
ArchetypeChunk is the core data structure that makes the ECS iteration efficient — systems iterate over contiguous arrays rather than following pointers.
Type Parameters
Section titled “Type Parameters”ECS_TYPE— the store type parameter
Constructor
Section titled “Constructor”public ArchetypeChunk(@Nonnull Store<ECS_TYPE> store, @Nonnull Archetype<ECS_TYPE> archetype)Methods
Section titled “Methods”@Nonnullpublic Archetype<ECS_TYPE> getArchetype()public int size()Returns the number of entities in this chunk.
@Nonnullpublic Ref<ECS_TYPE> getReferenceTo(int index)Returns the entity reference at the given index.
@Nullablepublic <T extends Component<ECS_TYPE>> T getComponent(int index, @Nonnull ComponentType<ECS_TYPE, T> componentType)Returns the component for entity at index, or null if the archetype does not include that component type.
public <T extends Component<ECS_TYPE>> void setComponent(int index, @Nonnull ComponentType<ECS_TYPE, T> componentType, @Nonnull T component)Replaces the component for entity at index.
public int addEntity(@Nonnull Ref<ECS_TYPE> ref, @Nonnull Holder<ECS_TYPE> holder)Adds an entity’s data from a Holder. Returns the entity’s index within this chunk.
@Nonnullpublic Holder<ECS_TYPE> removeEntity(int entityIndex, @Nonnull Holder<ECS_TYPE> target)Removes entity at entityIndex, copying its data into the target Holder. Uses swap-remove for O(1) removal.
@Nonnullpublic Holder<ECS_TYPE> copyEntity(int entityIndex, @Nonnull Holder<ECS_TYPE> target)Deep-copies entity data into the target Holder without removing the entity.
public void transferTo(@Nonnull Holder<ECS_TYPE> tempHolder, @Nonnull ArchetypeChunk<ECS_TYPE> chunk, @Nonnull Consumer<Holder<ECS_TYPE>> modification, @Nonnull IntObjectConsumer<Ref<ECS_TYPE>> referenceConsumer)Transfers all entities to another chunk, applying a modification to each entity’s holder during transfer. Used during archetype migration.