Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions src/main/kotlin/de/snowii/extractor/extractors/Entities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,42 @@ class Entities : Extractor.Extractor {

val entity = entityType.create(server.overworld(), EntitySpawnReason.NATURAL)
if (entity != null) {
if (entity is LivingEntity) {
entityJson.addProperty("max_health", entity.maxHealth)

if (entityName in TARGET_HURT_SOUND_ENTITIES) {
val hurtSound = getHurtSound(entity, damageSource)
val hurtSoundId = hurtSound?.let(BuiltInRegistries.SOUND_EVENT::getKey)?.path
if (hurtSoundId != null) {
entityJson.addProperty("hurt_sound", hurtSoundId)
}
if (entity is LivingEntity && entityName in TARGET_HURT_SOUND_ENTITIES) {
val hurtSound = getHurtSound(entity, damageSource)
val hurtSoundId = hurtSound?.let(BuiltInRegistries.SOUND_EVENT::getKey)?.path
if (hurtSoundId != null) {
entityJson.addProperty("hurt_sound", hurtSoundId)
}
}
entityJson.addProperty("attackable", entity.isAttackable)
entityJson.addProperty("mob", entity is Mob)
entityJson.addProperty("limit_per_chunk", (entity as? Mob)?.maxSpawnClusterSize ?: 0)
}

if (net.minecraft.world.entity.ai.attributes.DefaultAttributes.hasSupplier(entityType)) {
val supplier = net.minecraft.world.entity.ai.attributes.DefaultAttributes.getSupplier(entityType as net.minecraft.world.entity.EntityType<out LivingEntity>)

// Backwards compatibility for top-level max_health
val maxHealth = net.minecraft.world.entity.ai.attributes.Attributes.MAX_HEALTH
if (supplier.hasAttribute(maxHealth)) {
entityJson.addProperty("max_health", supplier.getBaseValue(maxHealth))
}

val attributesArray = JsonArray()
for (attribute in BuiltInRegistries.ATTRIBUTE) {
val holder = BuiltInRegistries.ATTRIBUTE.wrapAsHolder(attribute)
if (supplier.hasAttribute(holder)) {
val attrObj = JsonObject()
attrObj.addProperty(
BuiltInRegistries.ATTRIBUTE.getKey(attribute)!!.toString(),
supplier.getBaseValue(holder)
)
attributesArray.add(attrObj)
}
}
entityJson.add("attributes", attributesArray)
}

entityJson.addProperty("summonable", entityType.canSummon())
entityJson.addProperty("saveable", entityType.canSerialize())
entityJson.addProperty("fire_immune", entityType.fireImmune())
Expand Down