Skip to content
On this page
通用

KattonEntityApi

common/src/main/kotlin/top/katton/api/dpcaller/KattonEntityApi.kt
获取或设置 Entity 的 NBT 数据。

nbt

nbt通用属性
kotlin
var Entity.nbt: CompoundTag

获取或设置 Entity 的 NBT 数据。

KattonServerEntityCollection

KattonServerEntityCollection通用
kotlin
class KattonServerEntityCollection( private val server: MinecraftServer )

跨所有服务端关卡的实体集合。

属性

属性说明
serverMinecraftServer 实例。

KattonServerEntityCollection.all

KattonServerEntityCollection.all通用属性
kotlin
val all

所有关卡中的全部实体。

KattonServerEntityCollection.get

KattonServerEntityCollection.get通用函数
kotlin
operator fun get(level: ServerLevel): KattonLevelEntityCollection

获取指定关卡中的实体集合。

KattonServerEntityCollection.get

KattonServerEntityCollection.get通用函数
kotlin
operator fun get(uuid: UUID): Entity?

在所有关卡中按 UUID 查找实体。

KattonLevelEntityCollection

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

指定关卡中的实体集合。

属性

属性说明
level包含这些实体的 ServerLevel。

KattonLevelEntityCollection.get

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

获取与类型测试和谓词匹配的实体。

KattonLevelEntityCollection.get

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

获取 AABB 内与类型测试和谓词匹配的实体。

KattonLevelEntityCollection.get

KattonLevelEntityCollection.get通用函数
kotlin
operator fun get(selector: EntitySelector): List<Entity>

使用实体选择器获取实体。

KattonLevelEntityCollection.get

KattonLevelEntityCollection.get通用函数
kotlin
operator fun get(uuid: UUID): Entity?

在当前关卡中按 UUID 查找实体。

KattonEntityAttributeValueMap

KattonEntityAttributeValueMap通用
kotlin
class KattonEntityAttributeValueMap( val entity: LivingEntity )

用类似 Map 的方式访问生物实体的属性值。

属性

属性说明
entity要访问属性的 LivingEntity。

KattonEntityAttributeValueMap.contains

KattonEntityAttributeValueMap.contains通用函数
kotlin
fun contains(holder: Holder<Attribute>): Boolean

检查指定实体是否具有给定属性。

KattonEntityAttributeValueMap.get

KattonEntityAttributeValueMap.get通用函数
kotlin
operator fun get(holder: Holder<Attribute>): Double?

获取属性的当前值

KattonEntityAttributeValueMap.set

KattonEntityAttributeValueMap.set通用函数
kotlin
fun set(holder: Holder<Attribute>, value: Double, vararg modifiers: AttributeModifier)

设置属性的基础值,并可选添加修饰器。

attributeValues

attributeValues通用属性
kotlin
val LivingEntity.attributeValues

访问生物实体的属性值。

getAttribute

getAttribute通用函数
kotlin
fun getAttribute(entity: LivingEntity, attribute: Holder<Attribute>): Double

从 LivingEntity 获取属性值。

参数

参数说明
entity实体
attribute要读取的属性持有者。

返回值

返回属性值

hasAttribute

hasAttribute通用函数
kotlin
fun hasAttribute(entity: LivingEntity, attribute: Holder<Attribute>): Boolean

检查 LivingEntity 是否具有给定属性。

参数

参数说明
entity实体
attribute要检查的属性持有者。

返回值

如果属性存在则返回 true。

getBaseAttribute

getBaseAttribute通用函数
kotlin
fun getBaseAttribute(entity: LivingEntity, attribute: Holder<Attribute>): Double?

从 LivingEntity 获取基础属性值。

参数

参数说明
entity实体
attribute要读取的属性持有者

返回值

属性值;如果属性不存在则返回 null。

setBaseAttribute

setBaseAttribute通用函数
kotlin
fun setBaseAttribute(entity: LivingEntity, attribute: Holder<Attribute>, value: Double): Boolean

设置 LivingEntity 的基础属性值。

参数

参数说明
entity实体。
attribute要设置的属性持有者。
value新的基础值。

返回值

如果发生变化则返回 true,否则返回 false。

addAttributeModify

addAttributeModify通用函数
kotlin
fun addAttributeModify(entity: LivingEntity, attribute: Holder<Attribute>, modifier: AttributeModifier)

向实体添加临时属性修饰器。

参数

参数说明
entity实体。
attribute要修改的属性持有者。
modifier要添加的 AttributeModifier。

removeAttributeModify

removeAttributeModify通用函数
kotlin
fun removeAttributeModify(entity: LivingEntity, attribute: Holder<Attribute>, modifier: AttributeModifier)

从实体移除属性修饰器。

参数

参数说明
entity实体。
attribute要修改的属性持有者。
modifier要移除的 AttributeModifier。

damage

damage通用函数
kotlin
fun damage(entity: Entity, amount: Float)

使用通用伤害按指定数值伤害实体。

参数

参数说明
entity目标实体。
amount伤害值。

damage

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

使用伤害类型键,让攻击者对目标实体造成伤害。

参数

参数说明
target要伤害的实体。
amount伤害值。
attacker造成伤害的来源实体。
damageTypeDamageType 的资源键(默认 GENERIC)。

damage

damage通用函数
kotlin
fun damage(target: Entity, amount: Float, attacker: Entity, damageType: DamageType)

使用 DamageType 实例,让攻击者对目标实体造成伤害。

参数

参数说明
target要伤害的实体。
amount伤害值。
attacker造成伤害的来源实体。
damageType要应用的 DamageType 实例。

damage

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

使用伤害类型键,从指定位置对目标实体造成伤害。

参数

参数说明
target要伤害的实体。
amount伤害值。
pos伤害来源位置。
damageTypeDamageType 的资源键(默认 GENERIC)。

damage

damage通用函数
kotlin
fun damage(target: Entity, amount: Float, pos: Vec3, damageType: DamageType)

使用 DamageType 实例,从指定位置对目标实体造成伤害。

参数

参数说明
target要伤害的实体。
amount伤害值。
pos伤害来源位置。
damageType要应用的 DamageType 实例。

addEffect

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

向 LivingEntity 添加状态效果。

参数

参数说明
entity目标实体。
effect要应用的 MobEffect Holder。
duration效果持续时间,单位为 tick,默认 600。
amplifier效果放大等级,默认 0。
showParticles是否显示粒子。
ambient是否为环境效果。

removeEffect

removeEffect通用函数
kotlin
fun removeEffect(entity: LivingEntity, effect: Holder<MobEffect>)

从 LivingEntity 移除指定效果。

参数

参数说明
entity目标实体。
effect要移除的 MobEffect Holder。

clearEffects

clearEffects通用函数
kotlin
fun clearEffects(entity: LivingEntity)

清除 LivingEntity 身上的所有效果。

参数

参数说明
entity目标实体。

mount

mount通用函数
kotlin
fun mount(passenger: Entity, vehicle: Entity): Boolean

让乘客骑乘载具实体。

参数

参数说明
passenger要发起骑乘的实体。
vehicle要被骑乘的实体。

返回值

如果骑乘成功则返回 true,否则返回 false。

dismount

dismount通用函数
kotlin
fun dismount(passenger: Entity): Boolean

让乘客从载具上解除骑乘。

参数

参数说明
passenger要解除骑乘的实体。

返回值

如果已解除骑乘则返回 true,否则在未骑乘时返回 false。

rotate

rotate通用函数
kotlin
fun rotate(target: Entity, rot: Vec2, relative: Boolean = false)

使用 Vec2(pitch, yaw)旋转实体。

参数

参数说明
target目标实体。
rot旋转向量(x=pitch, y=yaw)。
relative是否按相对角度旋转。

rotate

rotate通用函数
kotlin
fun rotate(target: Entity, lookAt: Entity, targetAnchor: EntityAnchorArgument.Anchor = EntityAnchorArgument.Anchor.FEET, lookAtAnchor: EntityAnchorArgument.Anchor = EntityAnchorArgument.Anchor.FEET)

旋转实体,使其看向另一个实体。

参数

参数说明
target要旋转的实体。
lookAt要看向的实体。
targetAnchor目标实体上的锚点。
lookAtAnchor被看向实体上的锚点。

rotate

rotate通用函数
kotlin
fun rotate(target: Entity, lookAt: Vec3, targetAnchor: EntityAnchorArgument.Anchor = EntityAnchorArgument.Anchor.FEET, lookAtAnchor: EntityAnchorArgument.Anchor = EntityAnchorArgument.Anchor.FEET)

旋转实体,使其看向指定位置。

参数

参数说明
target要旋转的实体。
lookAt要看向的位置。
targetAnchor目标实体上的锚点。

spreadPlayers

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

将玩家分散到中心点周围。

参数

参数说明
level用作上下文的服务端关卡。
center中心位置向量(使用 x/z,忽略 y)。
spreadDistance玩家之间的最小距离。
maxRange最大分散半径。
maxHeight最大高度差。
respectTeams是否保持队伍成员在一起。
targets要分散的实体集合。

summon

summon通用函数
kotlin
fun summon(level: ServerLevel, id: String, vec3: Vec3, entityData: CompoundTag? = null): Entity?

在指定位置召唤给定类型的实体,并可选应用 NBT。

参数

参数说明
level用于生成实体的服务端关卡。
reference要召唤的 EntityType 引用。
vec3生成位置。
entityData可选的实体 NBT 覆盖数据。

返回值

返回生成的实体;失败时返回 null。

getTags

getTags通用函数
kotlin
fun getTags(entity: Entity): MutableCollection<String>

获取附加到实体上的标签。

参数

参数说明
entity目标实体。

返回值

返回标签字符串集合。

addTag

addTag通用函数
kotlin
fun addTag(entity: Entity, string: String): Boolean

向实体添加标签。

参数

参数说明
entity目标实体。
string要添加的标签。

返回值

如果标签已添加则返回 true,若已存在则返回 false。

removeTag

removeTag通用函数
kotlin
fun removeTag(entity: Entity, string: String): Boolean

从实体移除标签。

参数

参数说明
entity目标实体。
string要移除的标签。

返回值

如果标签已移除则返回 true。