Skip to content

Commit

Permalink
integrated registry: status effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Bixilon committed Dec 9, 2022
1 parent 84a6b4d commit 1d948bc
Show file tree
Hide file tree
Showing 28 changed files with 522 additions and 137 deletions.
Expand Up @@ -179,10 +179,6 @@ abstract class Entity(
}
}

for ((attribute, amplifier) in effects.processAttribute(name)) {
addToValue(attribute, amplifier)
}

return ret
}

Expand Down
Expand Up @@ -52,10 +52,10 @@ import de.bixilon.minosoft.data.entities.entities.player.compass.CompassPosition
import de.bixilon.minosoft.data.physics.PhysicsConstants
import de.bixilon.minosoft.data.registries.blocks.MinecraftBlocks
import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.effects.DefaultStatusEffects
import de.bixilon.minosoft.data.registries.effects.attributes.DefaultStatusEffectAttributeNames
import de.bixilon.minosoft.data.registries.effects.attributes.DefaultStatusEffectAttributes
import de.bixilon.minosoft.data.registries.effects.attributes.EntityAttribute
import de.bixilon.minosoft.data.registries.effects.movement.MovementEffect
import de.bixilon.minosoft.data.registries.enchantment.armor.ArmorEnchantment
import de.bixilon.minosoft.data.registries.item.MinecraftItems
import de.bixilon.minosoft.data.registries.item.items.Item
Expand Down Expand Up @@ -390,7 +390,7 @@ class LocalPlayerEntity(
var gravity = PhysicsConstants.BASE_GRAVITY
val falling = velocity.y <= 0.0

if (falling && effects[connection.registries.statusEffectRegistry[DefaultStatusEffects.SLOW_FALLING]] != null) {
if (falling && effects[MovementEffect.SlowFalling] != null) {
gravity = 0.01
fallDistance = 0.0
}
Expand Down Expand Up @@ -418,7 +418,7 @@ class LocalPlayerEntity(
val velocity = move(sidewaysSpeed, forwardSpeed, friction)


effects[connection.registries.statusEffectRegistry[DefaultStatusEffects.LEVITATION]]?.let {
effects[MovementEffect.Levitation]?.let {
velocity.y += (0.05 * (it.amplifier + 1.0f) - velocity.y) * 0.2 // ToDo: This should be correct, but somehow are we to fast...
} ?: let {
if (connection.world[positionInfo.chunkPosition] == null) {
Expand Down Expand Up @@ -534,7 +534,7 @@ class LocalPlayerEntity(
private fun jump() {
var velocity = 0.42 * jumpVelocityMultiplier

effects[connection.registries.statusEffectRegistry[DefaultStatusEffects.JUMP_BOOST]]?.let {
effects[MovementEffect.JumpBoost]?.let {
velocity += 0.1 * (it.amplifier + 1.0)
}
this.velocity.y = velocity
Expand Down
Expand Up @@ -17,9 +17,7 @@ import de.bixilon.kutil.collections.CollectionUtil.lockMapOf
import de.bixilon.kutil.collections.map.LockMap
import de.bixilon.minosoft.data.Tickable
import de.bixilon.minosoft.data.entities.StatusEffectInstance
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.effects.StatusEffectType
import de.bixilon.minosoft.data.registries.effects.attributes.EntityAttributeModifier

class StatusEffectProperty : Tickable {
private val effects: LockMap<StatusEffectType, StatusEffectInstance> = lockMapOf()
Expand Down Expand Up @@ -59,15 +57,4 @@ class StatusEffectProperty : Tickable {
operator fun contains(effect: StatusEffectType?): Boolean {
return effect in this.effects
}

fun processAttribute(name: ResourceLocation): MutableMap<EntityAttributeModifier, Int> {
val attributes: MutableMap<EntityAttributeModifier, Int> = mutableMapOf()
effects.lock.acquire()
for ((type, instance) in this.effects) {
val attribute = type.attributes[name] ?: continue
attributes[attribute] = instance.amplifier
}
effects.lock.release()
return attributes
}
}

This file was deleted.

@@ -0,0 +1,16 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.registries.effects

interface InstantEffect
@@ -0,0 +1,51 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.registries.effects

import de.bixilon.minosoft.data.registries.effects.damage.DamageEffect
import de.bixilon.minosoft.data.registries.effects.mining.MiningEffect
import de.bixilon.minosoft.data.registries.effects.other.OtherEffects
import de.bixilon.minosoft.data.registries.effects.vision.VisionEffect
import de.bixilon.minosoft.data.registries.integrated.IntegratedRegistry

object IntegratedStatusEffects : IntegratedRegistry<StatusEffectType>(
DamageEffect.Absorption,
DamageEffect.FireResistance,
DamageEffect.HealthBoost,
DamageEffect.InstantDamage,
DamageEffect.InstantHealth,
DamageEffect.Poison,
DamageEffect.Regeneration,
DamageEffect.Resistance,
DamageEffect.Strength,
DamageEffect.Weakness,
DamageEffect.Wither,

MiningEffect.Haste,
MiningEffect.MiningFatigue,

VisionEffect.Blindness,
VisionEffect.Nausea,
VisionEffect.NightVision,

OtherEffects.BadOmen,
OtherEffects.ConduitPower,
OtherEffects.Glowing,
OtherEffects.Hunger,
OtherEffects.Invisibility,
OtherEffects.Luck,
OtherEffects.Saturation,
OtherEffects.Unluck,
OtherEffects.WaterBreathing,
)
@@ -0,0 +1,46 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.registries.effects

import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.effects.properties.categories.CategorizedEffect
import de.bixilon.minosoft.data.registries.effects.properties.categories.StatusEffectCategories
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.text.formatting.color.Colored
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBColor

class PixlyzerStatusEffectType(
override val resourceLocation: ResourceLocation,
override val color: RGBColor,
override val category: StatusEffectCategories,
) : StatusEffectType(), Colored, CategorizedEffect {

override fun toString(): String {
return resourceLocation.full
}

companion object : ResourceLocationCodec<StatusEffectType> {

override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): PixlyzerStatusEffectType {

return PixlyzerStatusEffectType(
resourceLocation = resourceLocation,
category = data["category"]?.unsafeCast<String>()?.let { return@let StatusEffectCategories[it] } ?: StatusEffectCategories.NEUTRAL,
color = data["color"].unsafeCast<Int>().asRGBColor(),
)
}
}
}
Expand Up @@ -12,56 +12,8 @@
*/
package de.bixilon.minosoft.data.registries.effects

import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.json.JsonUtil.asJsonObject
import de.bixilon.kutil.json.JsonUtil.toJsonObject
import de.bixilon.minosoft.data.language.translate.Translatable
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.effects.attributes.EntityAttributeModifier
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBColor
import de.bixilon.minosoft.datafixer.rls.EntityAttributeFixer.fix
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import java.util.*

data class StatusEffectType(
override val resourceLocation: ResourceLocation,
val category: StatusEffectCategories?,
override val translationKey: ResourceLocation?,
val color: RGBColor,
val attributes: Map<ResourceLocation, EntityAttributeModifier>,
val uuidAttributes: Map<UUID, EntityAttributeModifier>,
) : RegistryItem(), Translatable {

override fun toString(): String {
return resourceLocation.full
}

companion object : ResourceLocationCodec<StatusEffectType> {

override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): StatusEffectType {
val attributes: MutableMap<ResourceLocation, EntityAttributeModifier> = mutableMapOf()
val uuidAttributes: MutableMap<UUID, EntityAttributeModifier> = mutableMapOf()

data["attributes"]?.toJsonObject()?.let {
for ((key, value) in it) {
val attribute = EntityAttributeModifier.deserialize(value.asJsonObject())
attributes[ResourceLocation.getResourceLocation(key).fix()] = attribute
uuidAttributes[attribute.uuid] = attribute
}
}

return StatusEffectType(
resourceLocation = resourceLocation,
category = data["category"]?.unsafeCast<String>()?.let { return@let StatusEffectCategories[it] },
translationKey = data["translation_key"]?.toResourceLocation(),
color = data["color"].unsafeCast<Int>().asRGBColor(),
attributes = attributes,
uuidAttributes = uuidAttributes,
)
}
}
abstract class StatusEffectType : RegistryItem() {
override val injectable: Boolean get() = false
}
@@ -0,0 +1,82 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.registries.effects.damage

import de.bixilon.minosoft.data.registries.CompanionResourceLocation
import de.bixilon.minosoft.data.registries.effects.InstantEffect
import de.bixilon.minosoft.data.registries.effects.StatusEffectType
import de.bixilon.minosoft.data.registries.effects.properties.categories.BeneficalEffect
import de.bixilon.minosoft.data.registries.effects.properties.categories.HarmfulEffect
import de.bixilon.minosoft.data.text.formatting.color.Colored
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBColor
import de.bixilon.minosoft.util.KUtil.minecraft

interface DamageEffect {


object Strength : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, BeneficalEffect {
override val RESOURCE_LOCATION = minecraft("strength")
override val color = 0x932423.asRGBColor()
}

object InstantHealth : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, BeneficalEffect, InstantEffect {
override val RESOURCE_LOCATION = minecraft("instand_health")
override val color = 0xF82423.asRGBColor()
}

object InstantDamage : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, HarmfulEffect, InstantEffect {
override val RESOURCE_LOCATION = minecraft("instant_damage")
override val color = 0x430A09.asRGBColor()
}

object Regeneration : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, BeneficalEffect {
override val RESOURCE_LOCATION = minecraft("regeneration")
override val color = 0xCD5CAB.asRGBColor()
}

object Resistance : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, BeneficalEffect {
override val RESOURCE_LOCATION = minecraft("resistance")
override val color = 0x99453A.asRGBColor()
}

object FireResistance : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, BeneficalEffect {
override val RESOURCE_LOCATION = minecraft("fire_resistance")
override val color = 0xE49A3A.asRGBColor()
}

object Weakness : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, HarmfulEffect {
override val RESOURCE_LOCATION = minecraft("weakness")
override val color = 0x484D48.asRGBColor()
}

object Poison : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, HarmfulEffect {
override val RESOURCE_LOCATION = minecraft("poison")
override val color = 0x4E9331.asRGBColor()
}

object Wither : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, HarmfulEffect {
override val RESOURCE_LOCATION = minecraft("wither")
override val color = 0x352A27.asRGBColor()
}

object HealthBoost : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, BeneficalEffect {
override val RESOURCE_LOCATION = minecraft("heath_boost")
override val color = 0xF87D23.asRGBColor()
}

object Absorption : StatusEffectType(), DamageEffect, CompanionResourceLocation, Colored, BeneficalEffect {
override val RESOURCE_LOCATION = minecraft("absorption")
override val color = 0x2552A5.asRGBColor()
}
}

0 comments on commit 1d948bc

Please sign in to comment.