save status effect modifiers

This commit is contained in:
Bixilon 2021-06-01 19:17:28 +02:00
parent 262f3bc3c6
commit 5a721a5a45
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 40 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.entities.meta.EntityMetaData
import de.bixilon.minosoft.data.inventory.InventorySlots.EquipmentSlots import de.bixilon.minosoft.data.inventory.InventorySlots.EquipmentSlots
import de.bixilon.minosoft.data.inventory.ItemStack import de.bixilon.minosoft.data.inventory.ItemStack
import de.bixilon.minosoft.data.mappings.effects.StatusEffect import de.bixilon.minosoft.data.mappings.effects.StatusEffect
import de.bixilon.minosoft.data.mappings.effects.attributes.StatusEffectAttribute
import de.bixilon.minosoft.data.mappings.entities.EntityType import de.bixilon.minosoft.data.mappings.entities.EntityType
import de.bixilon.minosoft.data.physics.PhysicsEntity import de.bixilon.minosoft.data.physics.PhysicsEntity
import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.data.text.ChatComponent
@ -45,6 +46,7 @@ abstract class Entity(
protected val random = Random protected val random = Random
val equipment: MutableMap<EquipmentSlots, ItemStack> = mutableMapOf() val equipment: MutableMap<EquipmentSlots, ItemStack> = mutableMapOf()
val activeStatusEffects: MutableMap<StatusEffect, StatusEffectInstance> = synchronizedMapOf() val activeStatusEffects: MutableMap<StatusEffect, StatusEffectInstance> = synchronizedMapOf()
val modifiers: MutableMap<UUID, StatusEffectAttribute> = synchronizedMapOf()
@JvmField @JvmField
protected val versionId: Int = connection.version.versionId protected val versionId: Int = connection.version.versionId
@ -73,6 +75,7 @@ abstract class Entity(
fun addEffect(effect: StatusEffectInstance) { fun addEffect(effect: StatusEffectInstance) {
// effect already applied, maybe the duration or the amplifier changed? // effect already applied, maybe the duration or the amplifier changed?
activeStatusEffects[effect.statusEffect] = effect activeStatusEffects[effect.statusEffect] = effect
// ToDo: Add status effect modifiers
} }
fun removeEffect(effect: StatusEffect) { fun removeEffect(effect: StatusEffect) {

View File

@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.mappings.effects
import com.google.gson.JsonObject import com.google.gson.JsonObject
import de.bixilon.minosoft.data.mappings.ResourceLocation import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.effects.attributes.StatusEffectAttribute
import de.bixilon.minosoft.data.mappings.registry.RegistryItem import de.bixilon.minosoft.data.mappings.registry.RegistryItem
import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer
import de.bixilon.minosoft.data.mappings.registry.Translatable import de.bixilon.minosoft.data.mappings.registry.Translatable
@ -21,6 +22,7 @@ import de.bixilon.minosoft.data.mappings.versions.Registries
import de.bixilon.minosoft.data.text.RGBColor import de.bixilon.minosoft.data.text.RGBColor
import de.bixilon.minosoft.data.text.RGBColor.Companion.asRGBColor import de.bixilon.minosoft.data.text.RGBColor.Companion.asRGBColor
import de.bixilon.minosoft.datafixer.EntityAttributeFixer.fix import de.bixilon.minosoft.datafixer.EntityAttributeFixer.fix
import java.util.*
data class StatusEffect( data class StatusEffect(
override val resourceLocation: ResourceLocation, override val resourceLocation: ResourceLocation,
@ -28,6 +30,7 @@ data class StatusEffect(
override val translationKey: String?, override val translationKey: String?,
val color: RGBColor, val color: RGBColor,
val attributes: Map<ResourceLocation, StatusEffectAttribute>, val attributes: Map<ResourceLocation, StatusEffectAttribute>,
val uuidAttributes: Map<UUID, StatusEffectAttribute>,
) : RegistryItem, Translatable { ) : RegistryItem, Translatable {
override fun toString(): String { override fun toString(): String {
@ -37,10 +40,13 @@ data class StatusEffect(
companion object : ResourceLocationDeserializer<StatusEffect> { companion object : ResourceLocationDeserializer<StatusEffect> {
override fun deserialize(mappings: Registries?, resourceLocation: ResourceLocation, data: JsonObject): StatusEffect { override fun deserialize(mappings: Registries?, resourceLocation: ResourceLocation, data: JsonObject): StatusEffect {
val attributes: MutableMap<ResourceLocation, StatusEffectAttribute> = mutableMapOf() val attributes: MutableMap<ResourceLocation, StatusEffectAttribute> = mutableMapOf()
val uuidAttributes: MutableMap<UUID, StatusEffectAttribute> = mutableMapOf()
data["attributes"]?.asJsonObject?.let { data["attributes"]?.asJsonObject?.let {
for ((key, value) in it.entrySet()) { for ((key, value) in it.entrySet()) {
attributes[ResourceLocation.getResourceLocation(key).fix()] = StatusEffectAttribute.deserialize(value.asJsonObject) val attribute = StatusEffectAttribute.deserialize(value.asJsonObject)
attributes[ResourceLocation.getResourceLocation(key).fix()] = attribute
uuidAttributes[attribute.uuid] = attribute
} }
} }
@ -49,7 +55,8 @@ data class StatusEffect(
category = StatusEffectCategories.NAME_MAP[data["category"].asString]!!, category = StatusEffectCategories.NAME_MAP[data["category"].asString]!!,
translationKey = data["translation_key"]?.asString, translationKey = data["translation_key"]?.asString,
color = data["color"].asInt.asRGBColor(), color = data["color"].asInt.asRGBColor(),
attributes.toMap(), attributes = attributes.toMap(),
uuidAttributes = uuidAttributes.toMap(),
) )
} }
} }

View File

@ -11,13 +11,11 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft. * This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/ */
package de.bixilon.minosoft.data.entities.attributes package de.bixilon.minosoft.data.mappings.effects.attributes
import de.bixilon.minosoft.util.KUtil.asResourceLocation import de.bixilon.minosoft.util.KUtil.asResourceLocation
object DefaultEntityAttributes { object DefaultStatusEffectAttributeNames {
// ToDo: They all had different names before 1.13
val GENERIC_MAX_HEALTH = "minecraft:generic.max_health".asResourceLocation() val GENERIC_MAX_HEALTH = "minecraft:generic.max_health".asResourceLocation()
val GENERIC_FOLLOW_RANGE = "minecraft:generic.follow_range".asResourceLocation() val GENERIC_FOLLOW_RANGE = "minecraft:generic.follow_range".asResourceLocation()
val GENERIC_KNOCKBACK_RESISTANCE = "minecraft:generic.knockback_resistance".asResourceLocation() val GENERIC_KNOCKBACK_RESISTANCE = "minecraft:generic.knockback_resistance".asResourceLocation()

View File

@ -0,0 +1,20 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.effects.attributes
import de.bixilon.minosoft.util.KUtil.asUUID
object DefaultStatusEffectAttributes {
val SPRINT_SPEED_BOOST = StatusEffectAttribute("Sprinting speed boost", "662A6B8D-DA3E-4C1C-8813-96EA6097278D".asUUID(), 0.30000001192092896f, StatusEffectOperations.MULTIPLY_TOTAL)
}

View File

@ -10,7 +10,7 @@
* *
* This software is not affiliated with Mojang AB, the original developer of Minecraft. * This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/ */
package de.bixilon.minosoft.data.mappings.effects package de.bixilon.minosoft.data.mappings.effects.attributes
import com.google.gson.JsonObject import com.google.gson.JsonObject
import de.bixilon.minosoft.util.Util import de.bixilon.minosoft.util.Util

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft. * This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/ */
package de.bixilon.minosoft.data.mappings.effects package de.bixilon.minosoft.data.mappings.effects.attributes
import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum import de.bixilon.minosoft.util.enum.ValuesEnum

View File

@ -138,4 +138,8 @@ object KUtil {
`false` `false`
} }
} }
fun String.asUUID(): UUID {
return Util.getUUIDFromString(this)
}
} }