Skip to content
On this page
Common

KattonEntityApi

common/src/main/kotlin/top/katton/api/dpcaller/KattonEntityApi.kt
Get/Set the NBT data of an Entity.

nbt ​

nbtCommonProperty
kotlin
var Entity.nbt: CompoundTag

Get/Set the NBT data of an Entity.

KattonServerEntityCollection ​

KattonServerEntityCollectionCommonClass
kotlin
class KattonServerEntityCollection( private val server: MinecraftServer )

Collection of all entities across all server levels.

Properties ​

PropertyDescription
serverThe MinecraftServer instance

KattonServerEntityCollection.all ​

KattonServerEntityCollection.allCommonProperty
kotlin
val all

All entities across all levels.

KattonServerEntityCollection.get ​

KattonServerEntityCollection.getCommonFunction
kotlin
operator fun get(level: ServerLevel): KattonLevelEntityCollection

Get entity collection for a specific level.

KattonServerEntityCollection.get ​

KattonServerEntityCollection.getCommonFunction
kotlin
operator fun get(uuid: UUID): Entity?

Find an entity by UUID across all levels.

KattonLevelEntityCollection ​

KattonLevelEntityCollectionCommonClass
kotlin
class KattonLevelEntityCollection( val level: ServerLevel ) : Iterable<Entity> by level.allEntities

Collection of entities within a specific level.

Properties ​

PropertyDescription
levelThe ServerLevel containing the entities

KattonLevelEntityCollection.get ​

KattonLevelEntityCollection.getCommonFunction
kotlin
operator fun <T : Entity> get(entityTypeTest: EntityTypeTest<Entity, T>, predicate: (T) -> Boolean = { true }): List<T>

Get entities matching a type test and predicate.

KattonLevelEntityCollection.get ​

KattonLevelEntityCollection.getCommonFunction
kotlin
operator fun <T : Entity> get(entityTypeTest: EntityTypeTest<Entity, T>, aabb: AABB, predicate: (T) -> Boolean = { true }): List<T>

Get entities within an AABB matching a type test and predicate.

KattonLevelEntityCollection.get ​

KattonLevelEntityCollection.getCommonFunction
kotlin
operator fun get(selector: EntitySelector): List<Entity>

Get entities using an entity selector.

KattonLevelEntityCollection.get ​

KattonLevelEntityCollection.getCommonFunction
kotlin
operator fun get(uuid: UUID): Entity?

Find an entity by UUID in this level.

KattonEntityAttributeValueMap ​

KattonEntityAttributeValueMapCommonClass
kotlin
class KattonEntityAttributeValueMap( val entity: LivingEntity )

Map-like access to a living entity's attribute values.

Properties ​

PropertyDescription
entityThe LivingEntity whose attributes are being accessed

KattonEntityAttributeValueMap.contains ​

KattonEntityAttributeValueMap.containsCommonFunction
kotlin
fun contains(holder: Holder<Attribute>): Boolean

Check if the entity has a given attribute.

KattonEntityAttributeValueMap.get ​

KattonEntityAttributeValueMap.getCommonFunction
kotlin
operator fun get(holder: Holder<Attribute>): Double?

Get the current value of an attribute.

KattonEntityAttributeValueMap.set ​

KattonEntityAttributeValueMap.setCommonFunction
kotlin
fun set(holder: Holder<Attribute>, value: Double, vararg modifiers: AttributeModifier)

Set the base value of an attribute and optionally add modifiers.

attributeValues ​

attributeValuesCommonProperty
kotlin
val LivingEntity.attributeValues

Access to a living entity's attribute values.

getAttribute ​

getAttributeCommonFunction
kotlin
fun getAttribute(entity: LivingEntity, attribute: Holder<Attribute>): Double

Get an attribute value from a LivingEntity.

Parameters ​

ParameterDescription
entitythe entity
attributeholder of the attribute to read

Returns ​

attribute value

hasAttribute ​

hasAttributeCommonFunction
kotlin
fun hasAttribute(entity: LivingEntity, attribute: Holder<Attribute>): Boolean

Check if a LivingEntity has a given attribute.

Parameters ​

ParameterDescription
entitythe entity
attributeholder of the attribute to check

Returns ​

if attribute present

getBaseAttribute ​

getBaseAttributeCommonFunction
kotlin
fun getBaseAttribute(entity: LivingEntity, attribute: Holder<Attribute>): Double?

Get base attribute value from a LivingEntity.

Parameters ​

ParameterDescription
entitythe entity
attributeholder of the attribute to check

Returns ​

base attribute value; null if attribute not present

setBaseAttribute ​

setBaseAttributeCommonFunction
kotlin
fun setBaseAttribute(entity: LivingEntity, attribute: Holder<Attribute>, value: Double): Boolean

Set the base attribute value for a LivingEntity.

Parameters ​

ParameterDescription
entitythe entity
attributeattribute holder to set
valuenew base value

Returns ​

if changed, false otherwise

addAttributeModify ​

addAttributeModifyCommonFunction
kotlin
fun addAttributeModify(entity: LivingEntity, attribute: Holder<Attribute>, modifier: AttributeModifier)

Add a transient attribute modifier to an entity.

Parameters ​

ParameterDescription
entitythe entity
attributeattribute holder to modify
modifierAttributeModifier to add

removeAttributeModify ​

removeAttributeModifyCommonFunction
kotlin
fun removeAttributeModify(entity: LivingEntity, attribute: Holder<Attribute>, modifier: AttributeModifier)

Remove an attribute modifier from an entity.

Parameters ​

ParameterDescription
entitythe entity
attributeattribute holder to modify
modifierAttributeModifier to remove

damage ​

damageCommonFunction
kotlin
fun damage(entity: Entity, amount: Float)

Damage an entity by an amount using generic damage.

Parameters ​

ParameterDescription
entitytarget entity
amountdamage amount

damage ​

damageCommonFunction
kotlin
fun damage(target: Entity, amount: Float, attacker: Entity, damageType: ResourceKey<DamageType> = DamageTypes.GENERIC)

Damage a target entity from an attacker using a damage type key.

Parameters ​

ParameterDescription
targetthe entity to damage
amountdamage amount
attackerthe source entity causing damage
damageTyperesource key of the DamageType (default GENERIC)

damage ​

damageCommonFunction
kotlin
fun damage(target: Entity, amount: Float, attacker: Entity, damageType: DamageType)

Damage a target entity from an attacker using a DamageType instance.

Parameters ​

ParameterDescription
targetthe entity to damage
amountdamage amount
attackerthe source entity causing damage
damageTypeDamageType instance to apply

damage ​

damageCommonFunction
kotlin
fun damage(target: Entity, amount: Float, pos: Vec3, damageType: ResourceKey<DamageType> = DamageTypes.GENERIC)

Damage a target entity from a position using a damage type key.

Parameters ​

ParameterDescription
targetentity to damage
amountdamage amount
posposition of damage source
damageTyperesource key of the DamageType (default GENERIC)

damage ​

damageCommonFunction
kotlin
fun damage(target: Entity, amount: Float, pos: Vec3, damageType: DamageType)

Damage a target entity from a position using a DamageType instance.

Parameters ​

ParameterDescription
targetentity to damage
amountdamage amount
posposition of damage source
damageTypeDamageType instance to apply

addEffect ​

addEffectCommonFunction
kotlin
fun addEffect(entity: LivingEntity, effect: Holder<MobEffect>, duration: Int = 600, amplifier: Int = 0, showParticles: Boolean = true, ambient: Boolean = false)

Add a mob effect to a LivingEntity.

Parameters ​

ParameterDescription
entitytarget entity
effectholder of the MobEffect to apply
durationeffect duration in ticks (default 600)
amplifiereffect amplifier level (default 0)
showParticleswhether to show particles
ambientwhether effect is ambient

removeEffect ​

removeEffectCommonFunction
kotlin
fun removeEffect(entity: LivingEntity, effect: Holder<MobEffect>)

Remove a specific effect from a LivingEntity.

Parameters ​

ParameterDescription
entitytarget entity
effectholder of the MobEffect to remove

clearEffects ​

clearEffectsCommonFunction
kotlin
fun clearEffects(entity: LivingEntity)

Clear all effects from a LivingEntity.

Parameters ​

ParameterDescription
entitytarget entity

mount ​

mountCommonFunction
kotlin
fun mount(passenger: Entity, vehicle: Entity): Boolean

Mount a passenger on a vehicle entity.

Parameters ​

ParameterDescription
passengerentity to mount
vehicleentity to be ridden

Returns ​

if mounting succeeded, false otherwise

dismount ​

dismountCommonFunction
kotlin
fun dismount(passenger: Entity): Boolean

Dismount a passenger from its vehicle.

Parameters ​

ParameterDescription
passengerentity to dismount

Returns ​

if dismounted, false if not riding

rotate ​

rotateCommonFunction
kotlin
fun rotate(target: Entity, rot: Vec2, relative: Boolean = false)

Rotate an entity by a Vec2 (pitch, yaw).

Parameters ​

ParameterDescription
targettarget entity
rotrotation vector (x=pitch, y=yaw)
relativewhether rotation is relative

rotate ​

rotateCommonFunction
kotlin
fun rotate(target: Entity, lookAt: Entity, targetAnchor: EntityAnchorArgument.Anchor = EntityAnchorArgument.Anchor.FEET, lookAtAnchor: EntityAnchorArgument.Anchor = EntityAnchorArgument.Anchor.FEET)

Rotate an entity to look at another entity.

Parameters ​

ParameterDescription
targetentity to rotate
lookAtentity to look at
targetAnchoranchor point on the target
lookAtAnchoranchor point on lookAt entity

rotate ​

rotateCommonFunction
kotlin
fun rotate(target: Entity, lookAt: Vec3, targetAnchor: EntityAnchorArgument.Anchor = EntityAnchorArgument.Anchor.FEET, lookAtAnchor: EntityAnchorArgument.Anchor = EntityAnchorArgument.Anchor.FEET)

Rotate an entity to look at a position.

Parameters ​

ParameterDescription
targetentity to rotate
lookAtposition to look at
targetAnchoranchor point on the target

spreadPlayers ​

spreadPlayersCommonFunction
kotlin
fun spreadPlayers(level: ServerLevel, center: Vec2, spreadDistance: Float, maxRange: Float, maxHeight: Int, respectTeams: Boolean, targets: Collection<Entity>)

Spread players around a center point.

Parameters ​

ParameterDescription
levelserver level used for context
centercenter position vector (x/z used, y ignored)
spreadDistanceminimum distance between players
maxRangemax spread radius
maxHeightmaximum height difference
respectTeamswhether to keep teams together
targetsentities to spread

summon ​

summonCommonFunction
kotlin
fun summon(level: ServerLevel, id: String, vec3: Vec3, entityData: CompoundTag? = null): Entity?

Summon an entity of a given type at a position with optional NBT.

Parameters ​

ParameterDescription
levelserver level to spawn in
referencereference to the EntityType to summon
vec3spawn position
entityDataoptional NBT override for the entity

Returns ​

Entity or null on failure

getTags ​

getTagsCommonFunction
kotlin
fun getTags(entity: Entity): MutableCollection<String>

Get tags attached to an entity.

Parameters ​

ParameterDescription
entitytarget entity

Returns ​

tag string collection

addTag ​

addTagCommonFunction
kotlin
fun addTag(entity: Entity, string: String): Boolean

Add a tag to an entity.

Parameters ​

ParameterDescription
entitytarget entity
stringtag to add

Returns ​

if tag was added, false if already present

removeTag ​

removeTagCommonFunction
kotlin
fun removeTag(entity: Entity, string: String): Boolean

Remove a tag from an entity.

Parameters ​

ParameterDescription
entitytarget entity
stringtag to remove

Returns ​

if the tag was removed