Class ArchetypeChunk<ECS_TYPE>

java.lang.Object
com.hypixel.hytale.component.ArchetypeChunk<ECS_TYPE>
Type Parameters:
ECS_TYPE - The ECS entity data type.

public class ArchetypeChunk<ECS_TYPE> extends Object
A chunk of entities that all share the same archetype and the same parent.
  • Constructor Details

    • ArchetypeChunk

      public ArchetypeChunk(@Nonnull Store<ECS_TYPE> store, @Nonnull Archetype<ECS_TYPE> archetype)
      Constructs a chunk that belongs to the store root.
      Parameters:
      store - The store that this chunk belongs to.
      archetype - The archetype describing what kind of entities that are in this chunk.
  • Method Details

    • emptyArray

      public static <ECS_TYPE> ArchetypeChunk<ECS_TYPE>[] emptyArray()
      Called to fetch and return an empty array of archetype chunks.
      Type Parameters:
      ECS_TYPE - the type of ECS
      Returns:
      an empty array of archetype chunks
    • getArchetype

      @Nonnull public Archetype<ECS_TYPE> getArchetype()
      Returns:
      the archetype describing what kind of entities that are in this chunk.
    • getParent

      @Nullable public Ref<ECS_TYPE> getParent()
      Returns:
      the entity that owns every entity in this chunk, or null for the store root.
    • size

      public int size()
      Returns:
      the number of entities in this chunk.
    • getReferenceTo

      @Nonnull public Ref<ECS_TYPE> getReferenceTo(int index)
      Called to fetch the entity reference of an entity at the given index.
      Parameters:
      index - The index of the entity.
      Returns:
      the entity reference.
    • setComponent

      public <T extends Component<ECS_TYPE>> void setComponent(int index, @Nonnull ComponentType<ECS_TYPE,T> componentType, @Nonnull T component)
      Called to set the component of an entity at the given index.
      Type Parameters:
      T - The type of component.
      Parameters:
      index - The index of the entity.
      componentType - The type of component to set.
      component - The component to set.
    • getComponent

      @Nullable public <T extends Component<ECS_TYPE>> T getComponent(int index, @Nonnull ComponentType<ECS_TYPE,T> componentType)
      Called to fetch the component of an entity at the given index.
      Type Parameters:
      T - The type of component.
      Parameters:
      index - The index of the entity.
      componentType - The type of component to fetch.
      Returns:
      the component, or null if the entity doesn't have the component.
    • addEntity

      public int addEntity(@Nonnull Ref<ECS_TYPE> ref, @Nonnull Holder<ECS_TYPE> holder)
      Called to add an entity to this chunk.
      Parameters:
      ref - The reference of the entity to add.
      holder - The holder of the entity to add.
      Returns:
      the index of the added entity.
    • addEntityFrom

      public void addEntityFrom(@Nonnull Ref<ECS_TYPE> ref, @Nonnull ArchetypeChunk<ECS_TYPE> source, int sourceIndex)
      Called to add an entity to this chunk by copying its components directly from a source chunk.
      Parameters:
      ref - The reference of the entity to add.
      source - The source chunk to copy components from.
      sourceIndex - The index of the entity in the source chunk.
    • addEntityFrom

      public void addEntityFrom(@Nonnull Ref<ECS_TYPE> ref, @Nonnull ArchetypeChunk<ECS_TYPE> source, int sourceIndex, @Nonnull ComponentType<ECS_TYPE,?> addedType, @Nonnull Component<ECS_TYPE> addedComponent)
      Called to add an entity to this chunk by copying its components directly from a source chunk, using addedComponent for the one-component type that does not exist in the source.
      Parameters:
      ref - The reference of the entity to add.
      source - The source chunk to copy components from.
      sourceIndex - The index of the entity in the source chunk.
      addedType - The component type being added (not present in source).
      addedComponent - The component instance to store for addedType.
    • copyEntity

      @Nonnull public Holder<ECS_TYPE> copyEntity(int entityIndex, @Nonnull Holder<ECS_TYPE> target)
      Called to copy an entity at the given index into the provided target holder.
      Parameters:
      entityIndex - The index of the entity to copy.
      target - The target holder to copy the entity into.
      Returns:
      the target holder.
    • copySerializableEntity

      @Nonnull public Holder<ECS_TYPE> copySerializableEntity(@Nonnull ComponentRegistry.Data<ECS_TYPE> data, int entityIndex, @Nonnull Holder<ECS_TYPE> target, @Nullable Predicate<ComponentType<ECS_TYPE,?>> filter)
      Called to copy the serializable components of an entity at the given index into the provided target holder.
      Parameters:
      data - The component data registry.
      entityIndex - The index of the entity to copy.
      target - The target holder to copy the entity into.
      Returns:
      the target holder.
    • removeEntity

      @Nonnull public Holder<ECS_TYPE> removeEntity(int entityIndex, @Nonnull Holder<ECS_TYPE> target)
      Called to remove an entity at the given index into the provided target holder.
      Parameters:
      entityIndex - The index of the entity to remove.
      target - The target holder to copy the entity into.
      Returns:
      the target holder.
    • transferTo

      public void transferTo(@Nonnull Holder<ECS_TYPE> tempInternalEntityHolder, @Nonnull ArchetypeChunk<ECS_TYPE> chunk, @Nonnull Consumer<Holder<ECS_TYPE>> modification, @Nonnull IntObjectConsumer<Ref<ECS_TYPE>> referenceConsumer)
      Called to transfer all entities in this chunk to the provided target chunk, applying the provided modification to each entity.
      Parameters:
      tempInternalEntityHolder - The temporary holder to use for transferring entities.
      chunk - The target chunk to transfer entities to.
      modification - The modification to apply to each entity before transferring.
      referenceConsumer - The consumer to accept the new entity index and reference after transfer.
    • transferSomeTo

      public void transferSomeTo(@Nonnull Holder<ECS_TYPE> tempInternalEntityHolder, @Nonnull ArchetypeChunk<ECS_TYPE> chunk, @Nonnull IntPredicate shouldTransfer, @Nonnull Consumer<Holder<ECS_TYPE>> modification, @Nonnull IntObjectConsumer<Ref<ECS_TYPE>> referenceConsumer)
      Called to transfer some entities in this chunk to the provided target chunk, applying the provided modification to each entity.
      Parameters:
      tempInternalEntityHolder - The temporary holder to use for transferring entities.
      chunk - The target chunk to transfer entities to.
      shouldTransfer - The predicate to determine which entities to transfer.
      modification - The modification to apply to each entity before transferring.
      referenceConsumer - The consumer to accept the new entity index and reference after transfer.
    • appendDump

      public void appendDump(@Nonnull String prefix, @Nonnull StringBuilder sb)
      Called to append a dump of this chunk to the provided string builder.
      Parameters:
      prefix - The prefix to use for each line.
      sb - The string builder to append to.
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object