Class AbstractEntityMethods
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract double
getEntityHeight
(@NotNull Entity entity) Retrieves the height of the specified entity.abstract double
getEntityWidth
(@NotNull Entity entity) Retrieves the width of the specified entity.abstract @NotNull Optional
<EntityType> getSpawnerType
(@Nullable ItemStack stack) Retrieves the entity type that a spawner item is configured to spawn.abstract void
setFromSpawner
(@NotNull Entity entity, boolean value) Sets whether the entity was spawned from a spawner block.boolean
setLoadChunks
(@NotNull Entity entity, boolean value) Sets whether the entity should force chunk loading.abstract void
Sets whether the entity should have AI enabled.abstract void
setPersists
(@NotNull Creature creature, boolean value) Sets whether the creature should persist (not despawn naturally).abstract @NotNull ItemStack
setSpawnerType
(@NotNull ItemStack stack, @NotNull EntityType type) Sets the entity type that a spawner item will spawn.
-
Constructor Details
-
AbstractEntityMethods
public AbstractEntityMethods()
-
-
Method Details
-
getEntityHeight
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
- theEntity
to get the height of- Returns:
- the height of the entity in blocks
-
getEntityWidth
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
- theEntity
to get the width of- Returns:
- the width of the entity in blocks
-
setPersists
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
- theCreature
to modifyvalue
-true
to make the creature persist,false
to allow natural despawning
-
setFromSpawner
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
- theEntity
to modifyvalue
-true
to mark as spawner-spawned,false
to mark as naturally spawned
-
setMobAI
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
- theEntity
to modifyvalue
-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 spawnerItemStack
to examine, may benull
- Returns:
- an
Optional
containing theEntityType
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 spawnerItemStack
to modifytype
- theEntityType
the spawner should spawn- Returns:
- the modified
ItemStack
with the new spawner type
-
setLoadChunks
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
- theEntity
to modifyvalue
-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
-