EffectiveEntity

abstract class EffectiveEntity

Base class for a custom entity type.

A subclass configures spawned entities via editEntity, picks a base getEntityType and declares identity through getNamespacedData. Each spawned entity is tagged with the type's namespaced key in persistent data, so plain Entity instances can be matched back via getNamespacedKeyByEntity / equalByNamespacedKey. Like the item/zone bases, the object must be instantiated (e.g. init() in onEnable) to register and start tracking. For example, EffectiveEntity.equalByNamespacedKey(firstEntity, secondEntity) tells whether two entities are the same custom type.

Live instances are cached automatically as chunks/worlds load and unload; query them with getEntities. Behaviours are added via addInteractHandler and doEntityNearLookable.

A built-in /emob <entity> command spawns any registered custom entity in-game.

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Backing cache of live entities of this type; kept in sync via chunk/world events.

Functions

Link copied to clipboard
fun addEntityToCache(entity: Entity)

Manually adds entity to the tracking cache (spawns do this automatically).

Link copied to clipboard
fun addInteractHandler(click: EffectiveAbstractInteract.Click, callback: InteractCallback, cooldownData: EffectiveAbstractInteract.CooldownData<EffectiveEntityInteractable.EventsCallOptions>? = null)

Registers an interact handler for entities of this custom type (matched by key). To instead handle a plain vanilla EntityType, register through EffectiveEntityInteractable.addInteractHandler with a non-custom entity.

Link copied to clipboard
fun additionalKey(name: String): NamespacedKey

Resolves the persistent-data key for the declared additional arg name — use it to read the per-entity value via EffectiveDataContainerUtils. See getAdditionalArgs for the full flow.

Link copied to clipboard
fun createEntity(location: Location?): Entity

Builds (but does not add to the world) an entity of this type at location — null falls back to the first world's origin. Use spawnEntity to actually place it.

fun createEntity(location: Location?, additionalArgs: List<String>): Entity

createEntity variant that also applies additionalArgs to the new entity.

Link copied to clipboard
fun doEntityNearLookable(whoToLook: (Entity) -> Boolean = EffectiveEntityLookable.Look.TO_NEAR_PLAYER, lookDistance: Float = 5.0f)

Makes entities of this type turn to look at nearby targets.

Link copied to clipboard
abstract fun editEntity(entity: Entity)

Configures a freshly created entity (attributes, name, equipment, …). Called on every create.

Link copied to clipboard

Declares extra, per-instance parameters this entity type accepts — values baked into an individual entity's persistent data at creation, so two entities of the same type can carry different settings.

Link copied to clipboard
fun getAdditionalArgsNamespacedKeys(): List<Pair<NamespacedKey, PersistentDataType<*, *>>>?

Namespaced keys backing this type's getAdditionalArgs (key → PDC type), or null if none.

Link copied to clipboard
fun getEntities(): ArrayList<Entity>

Currently tracked live entities of this type.

Link copied to clipboard

Convenience alias of getEntities for this type.

Link copied to clipboard
fun getEntitiesInBlock(block: Block): List<Entity>

Tracked entities of this type standing on the given block position.

Link copied to clipboard
abstract fun getEntityType(): EntityType

The base EntityType to spawn.

Link copied to clipboard
abstract fun getNamespacedData(): Pair<JavaPlugin, String>

Owning plugin and a plugin-unique id; together they form the getNamespacedKey.

Link copied to clipboard

Unique identity as "<plugin-name>/<id>", both lowercased.

Link copied to clipboard
fun removeEntityFromCache(entity: Entity)

Removes entity from the tracking cache (matched by UUID).

Link copied to clipboard
fun spawnEntity(location: Location): Entity

Creates and spawns an entity of this type at location, adding it to the tracking cache.

fun spawnEntity(location: Location, additionalArgs: List<String>): Entity

spawnEntity variant that also applies additionalArgs.