Class AbstractEntityMethods

java.lang.Object
com.kamikazejam.kamicommon.nms.abstraction.entity.AbstractEntityMethods

public abstract class AbstractEntityMethods extends Object
Abstract class providing version-specific implementations for entity manipulation and spawner item handling across different Minecraft versions.

This abstraction handles various entity-related operations that may differ between Minecraft versions, including entity dimensions, AI controls, persistence settings, and spawner item manipulation.

  • Constructor Details

    • AbstractEntityMethods

      public AbstractEntityMethods()
  • Method Details

    • getEntityHeight

      public abstract double getEntityHeight(@NotNull @NotNull Entity entity)
      Retrieves the height of the specified entity.

      This method returns the entity's bounding box height, which represents the vertical space the entity occupies in the world. This is useful for collision detection, spawning calculations, and space validation.

      Parameters:
      entity - the Entity to get the height of
      Returns:
      the height of the entity in blocks
    • getEntityWidth

      public abstract double getEntityWidth(@NotNull @NotNull Entity entity)
      Retrieves the width of the specified entity.

      This method returns the entity's bounding box width, which represents the horizontal space the entity occupies in the world. This is useful for collision detection, spawning calculations, and space validation.

      Parameters:
      entity - the Entity to get the width of
      Returns:
      the width of the entity in blocks
    • setPersists

      public abstract void setPersists(@NotNull @NotNull Creature creature, boolean value)
      Sets whether the creature should persist (not despawn naturally).

      When set to true, the creature will not despawn due to distance from players or other natural despawning conditions. This is useful for important NPCs or entities that should remain in the world permanently.

      Parameters:
      creature - the Creature to modify
      value - true to make the creature persist, false to allow natural despawning
    • setFromSpawner

      public abstract void setFromSpawner(@NotNull @NotNull Entity entity, boolean value)
      Sets whether the entity was spawned from a spawner block.

      This flag affects various entity behaviors, including experience drops and certain game mechanics. Entities spawned from spawners typically have different properties than naturally spawned entities.

      Parameters:
      entity - the Entity to modify
      value - true to mark as spawner-spawned, false to mark as naturally spawned
    • setMobAI

      public abstract void setMobAI(@NotNull @NotNull Entity entity, boolean value)
      Sets whether the entity should have AI enabled.

      When AI is disabled, the entity will not perform any autonomous behaviors such as movement, pathfinding, or attacking. The entity will remain static but can still be interacted with.

      Parameters:
      entity - the Entity to modify
      value - true to enable AI, false to disable AI
    • getSpawnerType

      @NotNull public abstract @NotNull Optional<EntityType> getSpawnerType(@Nullable @Nullable ItemStack stack)
      Retrieves the entity type that a spawner item is configured to spawn.

      This method examines a spawner ItemStack and determines what type of entity it will spawn when placed. The method handles version differences in how spawner data is stored.

      Parameters:
      stack - the spawner ItemStack to examine, may be null
      Returns:
      an Optional containing the EntityType if the stack is a valid spawner, empty otherwise
    • setSpawnerType

      @NotNull public abstract @NotNull ItemStack setSpawnerType(@NotNull @NotNull ItemStack stack, @NotNull @NotNull EntityType type)
      Sets the entity type that a spawner item will spawn.

      This method modifies a spawner ItemStack to spawn the specified entity type when placed. The method handles version differences in how spawner data is stored and applied.

      Parameters:
      stack - the spawner ItemStack to modify
      type - the EntityType the spawner should spawn
      Returns:
      the modified ItemStack with the new spawner type
    • setLoadChunks

      public boolean setLoadChunks(@NotNull @NotNull Entity entity, boolean value)
      Sets whether the entity should force chunk loading.

      When enabled, the entity will keep its chunk loaded even when no players are nearby. This is useful for entities that need to continue functioning regardless of player proximity.

      Note: This feature is only available in newer Minecraft versions. On unsupported versions, this method will return false and have no effect.

      Parameters:
      entity - the Entity to modify
      value - true to enable chunk loading, false to disable
      Returns:
      true if this method could be applied on the server version, false if the feature is not supported