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 doublegetEntityHeight(@NotNull Entity entity) Retrieves the height of the specified entity.abstract doublegetEntityWidth(@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 voidsetFromSpawner(@NotNull Entity entity, boolean value) Sets whether the entity was spawned from a spawner block.booleansetLoadChunks(@NotNull Entity entity, boolean value) Sets whether the entity should force chunk loading.abstract voidSets whether the entity should have AI enabled.abstract voidsetPersists(@NotNull Creature creature, boolean value) Sets whether the creature should persist (not despawn naturally).abstract @NotNull ItemStacksetSpawnerType(@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- theEntityto 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- theEntityto 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- theCreatureto modifyvalue-trueto make the creature persist,falseto 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- theEntityto modifyvalue-trueto mark as spawner-spawned,falseto 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- theEntityto modifyvalue-trueto enable AI,falseto 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
ItemStackand determines what type of entity it will spawn when placed. The method handles version differences in how spawner data is stored.- Parameters:
stack- the spawnerItemStackto examine, may benull- Returns:
- an
Optionalcontaining theEntityTypeif 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
ItemStackto spawn the specified entity type when placed. The method handles version differences in how spawner data is stored and applied.- Parameters:
stack- the spawnerItemStackto modifytype- theEntityTypethe spawner should spawn- Returns:
- the modified
ItemStackwith 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
falseand have no effect.- Parameters:
entity- theEntityto modifyvalue-trueto enable chunk loading,falseto disable- Returns:
trueif this method could be applied on the server version,falseif the feature is not supported
-