Class SnapshotBuffer

java.lang.Object
com.hypixel.hytale.server.core.modules.entity.component.SnapshotBuffer
All Implemented Interfaces:
Component<EntityStore>, Cloneable

public class SnapshotBuffer extends Object implements Component<EntityStore>
Stores a short history of an entity's hit detection state.

History is stored as flat double/float arrays, packed three components per tick slot, since this is written for every ticking entity every tick and only read back occasionally. EntitySnapshot instances are only materialized on read.

  • Constructor Details

    • SnapshotBuffer

      public SnapshotBuffer()
  • Method Details

    • getComponentType

      public static ComponentType<EntityStore, SnapshotBuffer> getComponentType()
    • getSnapshotClamped

      @Nonnull public EntitySnapshot getSnapshotClamped(int tickIndex)
      Returns the snapshot of the entity's hit-detection information as it was at the given tick index.

      If the tick index is older than the oldest stored snapshot that snapshot will be returned instead.

      Parameters:
      tickIndex - The tick index to find the snapshot of.
      Returns:
      The nearest snapshot to the given tick index.
      Throws:
      IllegalStateException - If the snapshot buffer hasn't be initialized with at least one snapshot
      IllegalArgumentException - If the tickIndex requested is newer than any stored snapshot.
    • getSnapshot

      @Nullable public EntitySnapshot getSnapshot(int tickIndex)
      Returns the snapshot of the entity's hit-detection information as it was at the given tick index.
      Parameters:
      tickIndex - The tick index to find the snapshot of.
      Returns:
      The snapshot at the given tick index or null.
      Throws:
      IllegalArgumentException - If the tickIndex requested is newer than any stored snapshot.
    • storeSnapshot

      public void storeSnapshot(int tickIndex, @Nonnull org.joml.Vector3d position, @Nonnull Rotation3f bodyRotation)
      Stores the given information in a snapshot for the given tickIndex.

      If the tickIndex isn't the next expected tick then this buffer will be cleared first to prevent gaps.

      Parameters:
      tickIndex - The tick index to store this snapshot for
      position - The position of the entity to store in the snapshot
      bodyRotation - The body rotation to store in the snapshot
    • resize

      public void resize(int newLength)
      Clears and resizes the snapshot buffer to the given size.

      Does nothing if the snapshot buffer is already the correct size.

      Parameters:
      newLength - The new size of the buffer.
      Throws:
      IllegalArgumentException - If the new size is <= 0
    • isInitialized

      public boolean isInitialized()
    • getCurrentTickIndex

      public int getCurrentTickIndex()
    • getOldestTickIndex

      public int getOldestTickIndex()
    • clone

      @Nonnull public Component<EntityStore> clone()
      Specified by:
      clone in interface Component<EntityStore>
      Returns:
      a clone instance of the original component instance.