diff --git a/src/main/kotlin/de/snowii/extractor/extractors/Entities.kt b/src/main/kotlin/de/snowii/extractor/extractors/Entities.kt index e1b2971..4527e99 100644 --- a/src/main/kotlin/de/snowii/extractor/extractors/Entities.kt +++ b/src/main/kotlin/de/snowii/extractor/extractors/Entities.kt @@ -34,15 +34,11 @@ 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) @@ -50,6 +46,30 @@ class Entities : Extractor.Extractor { 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) + + // 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())