mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
save status effect modifiers
This commit is contained in:
parent
262f3bc3c6
commit
5a721a5a45
@ -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.ItemStack
|
||||
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.physics.PhysicsEntity
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
@ -45,6 +46,7 @@ abstract class Entity(
|
||||
protected val random = Random
|
||||
val equipment: MutableMap<EquipmentSlots, ItemStack> = mutableMapOf()
|
||||
val activeStatusEffects: MutableMap<StatusEffect, StatusEffectInstance> = synchronizedMapOf()
|
||||
val modifiers: MutableMap<UUID, StatusEffectAttribute> = synchronizedMapOf()
|
||||
|
||||
@JvmField
|
||||
protected val versionId: Int = connection.version.versionId
|
||||
@ -73,6 +75,7 @@ abstract class Entity(
|
||||
fun addEffect(effect: StatusEffectInstance) {
|
||||
// effect already applied, maybe the duration or the amplifier changed?
|
||||
activeStatusEffects[effect.statusEffect] = effect
|
||||
// ToDo: Add status effect modifiers
|
||||
}
|
||||
|
||||
fun removeEffect(effect: StatusEffect) {
|
||||
|
@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.mappings.effects
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
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.ResourceLocationDeserializer
|
||||
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.Companion.asRGBColor
|
||||
import de.bixilon.minosoft.datafixer.EntityAttributeFixer.fix
|
||||
import java.util.*
|
||||
|
||||
data class StatusEffect(
|
||||
override val resourceLocation: ResourceLocation,
|
||||
@ -28,6 +30,7 @@ data class StatusEffect(
|
||||
override val translationKey: String?,
|
||||
val color: RGBColor,
|
||||
val attributes: Map<ResourceLocation, StatusEffectAttribute>,
|
||||
val uuidAttributes: Map<UUID, StatusEffectAttribute>,
|
||||
) : RegistryItem, Translatable {
|
||||
|
||||
override fun toString(): String {
|
||||
@ -37,10 +40,13 @@ data class StatusEffect(
|
||||
companion object : ResourceLocationDeserializer<StatusEffect> {
|
||||
override fun deserialize(mappings: Registries?, resourceLocation: ResourceLocation, data: JsonObject): StatusEffect {
|
||||
val attributes: MutableMap<ResourceLocation, StatusEffectAttribute> = mutableMapOf()
|
||||
val uuidAttributes: MutableMap<UUID, StatusEffectAttribute> = mutableMapOf()
|
||||
|
||||
data["attributes"]?.asJsonObject?.let {
|
||||
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]!!,
|
||||
translationKey = data["translation_key"]?.asString,
|
||||
color = data["color"].asInt.asRGBColor(),
|
||||
attributes.toMap(),
|
||||
attributes = attributes.toMap(),
|
||||
uuidAttributes = uuidAttributes.toMap(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,11 @@
|
||||
* 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
|
||||
|
||||
object DefaultEntityAttributes {
|
||||
// ToDo: They all had different names before 1.13
|
||||
|
||||
object DefaultStatusEffectAttributeNames {
|
||||
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()
|
@ -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)
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
* 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 de.bixilon.minosoft.util.Util
|
@ -11,7 +11,7 @@
|
||||
* 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.enum.ValuesEnum
|
@ -138,4 +138,8 @@ object KUtil {
|
||||
`false`
|
||||
}
|
||||
}
|
||||
|
||||
fun String.asUUID(): UUID {
|
||||
return Util.getUUIDFromString(this)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user