diff --git a/src/main/java/de/bixilon/minosoft/data/entities/attributes/DefaultEntityAttributes.kt b/src/main/java/de/bixilon/minosoft/data/entities/attributes/DefaultEntityAttributes.kt
new file mode 100644
index 000000000..d2be5e562
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/data/entities/attributes/DefaultEntityAttributes.kt
@@ -0,0 +1,28 @@
+/*
+ * Minosoft
+ * Copyright (C) 2021 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.data.entities.attributes
+
+import de.bixilon.minosoft.util.KUtil.asResourceLocation
+
+object DefaultEntityAttributes {
+ // ToDo
+
+ val GENERIC_MAX_HEALTH = "minecraft:generic.max_health".asResourceLocation()
+ val GENERIC_FOLLOW_RANGE = "minecraft:generic.follow_range".asResourceLocation()
+ val GENERIC_KNOCKBACK_RESISTANCE = "minecraft:generic.knockback_resistance".asResourceLocation()
+ val GENERIC_MOVEMENT_SPEED = "minecraft:generic.movement_speed".asResourceLocation()
+ val GENERIC_ATTACK_KNOCKBACK = "minecraft:generic.attack_knockback".asResourceLocation()
+ val GENERIC_ARMOR = "minecraft:generic.armor".asResourceLocation()
+ val GENERIC_ARMOR_TOUGHNESS = "minecraft:generic.armor_toughness".asResourceLocation()
+}
diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt
index bcbc8d74f..3711d5914 100644
--- a/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt
+++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt
@@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.entities.entities
import de.bixilon.minosoft.data.entities.EntityMetaDataFields
import de.bixilon.minosoft.data.entities.EntityRotation
+import de.bixilon.minosoft.data.entities.attributes.DefaultEntityAttributes
import de.bixilon.minosoft.data.mappings.entities.EntityType
import de.bixilon.minosoft.data.player.Hands
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
@@ -44,7 +45,7 @@ abstract class LivingEntity(connection: PlayConnection, entityType: EntityType,
get() {
val meta = entityMetaData.sets.getFloat(EntityMetaDataFields.LIVING_ENTITY_HEALTH)
return if (meta == Float.MIN_VALUE) {
- entityType.maxHealth
+ entityType.attributes[DefaultEntityAttributes.GENERIC_MAX_HEALTH] ?: 1.0f
} else {
meta
}
diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/entities/EntityType.kt b/src/main/java/de/bixilon/minosoft/data/mappings/entities/EntityType.kt
index 051a90002..b8ccbbf5a 100644
--- a/src/main/java/de/bixilon/minosoft/data/mappings/entities/EntityType.kt
+++ b/src/main/java/de/bixilon/minosoft/data/mappings/entities/EntityType.kt
@@ -24,6 +24,7 @@ import de.bixilon.minosoft.data.mappings.registry.RegistryItem
import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer
import de.bixilon.minosoft.data.mappings.registry.Translatable
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
+import de.bixilon.minosoft.datafixer.EntityAttributeFixer.fix
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import glm_.vec3.Vec3
@@ -34,7 +35,7 @@ data class EntityType(
val height: Float,
val sizeFixed: Boolean,
val fireImmune: Boolean,
- val maxHealth: Float,
+ val attributes: Map,
val factory: EntityFactory,
) : RegistryItem, Translatable {
@@ -57,6 +58,14 @@ data class EntityType(
return null
}
+ val attributes: MutableMap = mutableMapOf()
+
+ data["attributes"]?.asJsonObject?.let {
+ for ((attributeResourceLocation, value) in it.entrySet()) {
+ attributes[ResourceLocation.getPathResourceLocation(attributeResourceLocation).fix()] = value.asFloat
+ }
+ }
+
return EntityType(
resourceLocation = resourceLocation,
translationKey = data["translation_key"]?.asString,
@@ -64,7 +73,7 @@ data class EntityType(
height = data["height"].asFloat,
fireImmune = data["fire_immune"]?.asBoolean ?: false,
sizeFixed = data["size_fixed"]?.asBoolean ?: false,
- maxHealth = data["minecraft:generic.max_health"]?.asFloat ?: Float.MAX_VALUE,
+ attributes = attributes.toMap(),
factory = DefaultEntityFactories.getEntityFactory(resourceLocation) ?: error("Can not find entity factory for $resourceLocation"),
)
}
diff --git a/src/main/java/de/bixilon/minosoft/datafixer/DataFixerUtil.kt b/src/main/java/de/bixilon/minosoft/datafixer/DataFixerUtil.kt
new file mode 100644
index 000000000..b0fe81ab1
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/datafixer/DataFixerUtil.kt
@@ -0,0 +1,26 @@
+/*
+ * Minosoft
+ * Copyright (C) 2021 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.datafixer
+
+import de.bixilon.minosoft.data.mappings.ResourceLocation
+
+object DataFixerUtil {
+ fun Map.asResourceLocationMap(): Map {
+ val out: MutableMap = mutableMapOf()
+ for ((key, value) in this) {
+ out[ResourceLocation.getResourceLocation(key)] = ResourceLocation.getResourceLocation(value)
+ }
+ return out.toMap()
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/datafixer/EntityAttributeFixer.kt b/src/main/java/de/bixilon/minosoft/datafixer/EntityAttributeFixer.kt
new file mode 100644
index 000000000..1ebaa7b42
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/datafixer/EntityAttributeFixer.kt
@@ -0,0 +1,44 @@
+/*
+ * Minosoft
+ * Copyright (C) 2021 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.datafixer
+
+import de.bixilon.minosoft.data.mappings.ResourceLocation
+import de.bixilon.minosoft.datafixer.DataFixerUtil.asResourceLocationMap
+
+object EntityAttributeFixer {
+ private val RENAMES: Map = mapOf(
+ "generic.maxHealth" to "generic.max_health",
+ "zombie.spawnReinforcements" to "zombie.spawn_reinforcements",
+
+ "horse.jumpStrength" to "horse.jump_strength",
+
+ "generic.followRange" to "generic.follow_range",
+
+ "generic.knockbackResistance" to "generic.knockback_resistance",
+
+ "generic.movementSpeed" to "generic.movement_speed",
+
+ "generic.flyingSpeed" to "generic.flying_speed",
+
+ "generic.attackDamage" to "generic.attack_damage",
+ "generic.attackKnockback" to "generic.attack_knockback",
+ "generic.attackSpeed" to "generic.attack_speed",
+ "generic.armorToughness" to "generic.armor_toughness",
+ ).asResourceLocationMap()
+
+
+ fun ResourceLocation.fix(): ResourceLocation {
+ return RENAMES.getOrDefault(this, this)
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PlayerAbilitiesS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PlayerAbilitiesS2CP.kt
index df595049e..d7142e4d5 100644
--- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PlayerAbilitiesS2CP.kt
+++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PlayerAbilitiesS2CP.kt
@@ -31,7 +31,7 @@ class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
init {
val flags = buffer.readUnsignedByte()
if (buffer.versionId < ProtocolVersions.V_14W03B) { // ToDo: Find out correct version
- isInvulnerable = flags isBit (0)
+ isInvulnerable = flags.isBit(0)
isFlying = flags.isBit(1)
canFly = flags.isBit(2)
canInstantBuild = flags.isBit(3)
diff --git a/src/main/java/de/bixilon/minosoft/util/KUtil.kt b/src/main/java/de/bixilon/minosoft/util/KUtil.kt
index e7f6cab85..141ddd49a 100644
--- a/src/main/java/de/bixilon/minosoft/util/KUtil.kt
+++ b/src/main/java/de/bixilon/minosoft/util/KUtil.kt
@@ -13,6 +13,7 @@
package de.bixilon.minosoft.util
+import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.util.enum.AliasableEnum
import java.util.*
@@ -48,4 +49,8 @@ object KUtil {
}
return null
}
+
+ fun String.asResourceLocation(): ResourceLocation {
+ return ResourceLocation(this)
+ }
}