From dc4d4e1107f0426a7fb9741fb23d6efa293462bf Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Sat, 12 Oct 2024 17:15:08 -0500 Subject: [PATCH 1/3] [fix] Separate literal attribute value from skill point allocation --- .../ui/components/AttributeComponent.kt | 2 +- .../labels/AttributeLabelComponent.kt | 25 ++++++++--- .../ui/menus/PlayerEXAttributesMenu.kt | 2 +- .../components/player/PlayerDataComponent.kt | 43 +++++++++---------- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/client/kotlin/com/bibireden/playerex/ui/components/AttributeComponent.kt b/src/client/kotlin/com/bibireden/playerex/ui/components/AttributeComponent.kt index 24a85ae2..274fd5df 100644 --- a/src/client/kotlin/com/bibireden/playerex/ui/components/AttributeComponent.kt +++ b/src/client/kotlin/com/bibireden/playerex/ui/components/AttributeComponent.kt @@ -24,7 +24,7 @@ import net.minecraft.network.chat.Component private val StackingBehavior.symbol: String get() = if (this == StackingBehavior.Add) "+" else "×" -class AttributeComponent(private val attribute: Attribute, private val player: Player, component: IPlayerDataComponent) : FlowLayout(Sizing.fill(100), Sizing.fixed(18), Algorithm.HORIZONTAL) { +class AttributeComponent(private val attribute: Attribute, private val player: Player, val component: IPlayerDataComponent) : FlowLayout(Sizing.fill(100), Sizing.fixed(18), Algorithm.HORIZONTAL) { val label: AttributeLabelComponent fun refresh() { diff --git a/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeLabelComponent.kt b/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeLabelComponent.kt index d9c13978..1bdb60ad 100644 --- a/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeLabelComponent.kt +++ b/src/client/kotlin/com/bibireden/playerex/ui/components/labels/AttributeLabelComponent.kt @@ -2,6 +2,7 @@ package com.bibireden.playerex.ui.components.labels import com.bibireden.data_attributes.api.DataAttributesAPI import com.bibireden.data_attributes.api.attribute.IEntityAttribute +import com.bibireden.playerex.ext.component import com.bibireden.playerex.ext.id import com.bibireden.playerex.ui.util.Colors import io.wispforest.owo.ui.component.LabelComponent @@ -11,11 +12,25 @@ import net.minecraft.world.entity.ai.attributes.Attribute import net.minecraft.world.entity.player.Player import net.minecraft.network.chat.Component -private fun createTextFromAttribute(attribute: Attribute, player: Player) = Component.literal("(") - .append(Component.literal("${DataAttributesAPI.getValue(attribute, player).map(Double::toInt).orElse(0)}").withStyle { - it.withColor(Colors.GOLD) - }) - .append("/${(attribute as IEntityAttribute).`data_attributes$max`().toInt()})") +private fun createTextFromAttribute(attribute: Attribute, player: Player): Component { + val allocatedPoints = player.component.get(attribute).toInt() + val actual = DataAttributesAPI.getValue(attribute, player).map(Double::toInt).orElse(0) + + val text = Component.literal("(") + .append(Component.literal("$allocatedPoints").withStyle { + it.withColor(Colors.GOLD) + }) + .append("/${(attribute as IEntityAttribute).`data_attributes$max`().toInt()})") + + val difference = actual - allocatedPoints + if (difference > 0) { + text.append(" [").append(Component.literal("+$difference").withStyle { + it.withColor(Colors.DARK_GREEN) + }).append("]") + } + + return text +} open class AttributeLabelComponent(private val attribute: Attribute, private val player: Player) : LabelComponent(Component.empty()) { init { diff --git a/src/client/kotlin/com/bibireden/playerex/ui/menus/PlayerEXAttributesMenu.kt b/src/client/kotlin/com/bibireden/playerex/ui/menus/PlayerEXAttributesMenu.kt index c5109784..05816950 100644 --- a/src/client/kotlin/com/bibireden/playerex/ui/menus/PlayerEXAttributesMenu.kt +++ b/src/client/kotlin/com/bibireden/playerex/ui/menus/PlayerEXAttributesMenu.kt @@ -81,7 +81,7 @@ class PlayerEXAttributesMenu : MenuComponent(algorithm = Algorithm.HORIZONTAL) { this.forEachDescendant { descendant -> if (descendant is AttributeButtonComponent) { val max = descendant.attribute.`data_attributes$max`() - val current = DataAttributesAPI.getValue(descendant.attribute, player).orElse(0.0) + val current = component.get(descendant.attribute) when (descendant.type) { PlayerEXScreen.ButtonType.Add -> descendant.active(result > 0 && component.skillPoints >= result && (current + result) <= max) PlayerEXScreen.ButtonType.Remove -> descendant.active(result > 0 && component.refundablePoints > 0 && (current - result >= 0)) diff --git a/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt b/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt index dca75348..b2dc72ae 100644 --- a/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt +++ b/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt @@ -197,35 +197,34 @@ class PlayerDataComponent( override fun skillUp(skill: Attribute, amount: Int, override: Boolean): Boolean { if (amount <= 0) return false - return DataAttributesAPI.getValue(skill, player).map { current -> - val expected = current + amount - // too high - if (expected > (skill as IEntityAttribute).`data_attributes$max`()) return@map false - if (!override) { - // not enough skill points - if (skillPoints < amount) return@map false - this._skillPoints -= amount - } - this.set(skill, expected.toInt()) - // signal to a client that an increase has occurred... - NetworkingChannels.NOTIFICATIONS.serverHandle(player).send(NetworkingPackets.Notify(NotificationType.Spent)) - return@map true - }.orElse(false) + val current = _modifiers.getOrDefault(skill.id, 0.0) + val expected = current + amount + // too high + if (expected > skill.`data_attributes$max`()) return false + if (!override) { + // not enough skill points + if (skillPoints < amount) return false + this._skillPoints -= amount + } + this.set(skill, expected.toInt()) + // signal to a client that an increase has occurred... + NetworkingChannels.NOTIFICATIONS.serverHandle(player).send(NetworkingPackets.Notify(NotificationType.Spent)) + return true } override fun refund(skill: Attribute, amount: Int): Boolean { if (amount <= 0 || this.refundablePoints < amount) return false - return DataAttributesAPI.getValue(skill, player).map { value -> - if (amount > value) return@map false - this.addRefundablePoints(-amount) - this.addSkillPoints(amount) - this.set(skill, (value - amount).toInt()) + val value = _modifiers.getOrDefault(skill.id, 0.0) + if (amount > value) return false - ServerNetworkingFactory.notify(player, NotificationType.Refunded) + this.addRefundablePoints(-amount) + this.addSkillPoints(amount) + this.set(skill, (value - amount).toInt()) - true - }.orElse(false) + ServerNetworkingFactory.notify(player, NotificationType.Refunded) + + return true } val modifiers: Map From 99d562d718e686082ee72612cdb4764f8b26ec5e Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Sat, 12 Oct 2024 17:35:57 -0500 Subject: [PATCH 2/3] [ref] use actual component instead of getting it again --- .../components/player/PlayerDataComponent.kt | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt b/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt index b2dc72ae..09fc0635 100644 --- a/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt +++ b/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt @@ -1,7 +1,5 @@ package com.bibireden.playerex.components.player -import com.bibireden.data_attributes.api.DataAttributesAPI -import com.bibireden.data_attributes.api.attribute.IEntityAttribute import com.bibireden.data_attributes.endec.Endecs import com.bibireden.data_attributes.endec.nbt.NbtDeserializer import com.bibireden.data_attributes.endec.nbt.NbtSerializer @@ -172,26 +170,25 @@ class PlayerDataComponent( override fun levelUp(amount: Int, override: Boolean): Boolean { if (amount <= 0) return false - return DataAttributesAPI.getValue(PlayerEXAttributes.LEVEL, player).map { level -> - val expectedLevel = level + amount - // get the expected level, but do not go beyond the bounds of the maximum! - if (expectedLevel > PlayerEXAttributes.LEVEL.maxValue) return@map false + val level = this.get(PlayerEXAttributes.LEVEL) + val expectedLevel = level + amount + // get the expected level, but do not go beyond the bounds of the maximum! + if (expectedLevel > PlayerEXAttributes.LEVEL.maxValue) return false - val required = PlayerEXUtil.getRequiredXpForLevel(player, expectedLevel) + val required = PlayerEXUtil.getRequiredXpForLevel(player, expectedLevel) - val isEnoughExperience = player.experienceLevel >= required || override - if (isEnoughExperience) { - val skillPoints = CONFIG.skillPointsPerLevelUp * amount - val component = PlayerEXComponents.PLAYER_DATA.get(player) + val isEnoughExperience = player.experienceLevel >= required || override + if (isEnoughExperience) { + val skillPoints = CONFIG.skillPointsPerLevelUp * amount - if (!override) player.giveExperienceLevels(-required) - component.addSkillPoints(skillPoints) - component.set(PlayerEXAttributes.LEVEL, expectedLevel.toInt()) + if (!override) player.giveExperienceLevels(-required) + this.addSkillPoints(skillPoints) + this.set(PlayerEXAttributes.LEVEL, expectedLevel.toInt()) - ServerNetworkingFactory.notify(player, NotificationType.Spent) - } - return@map isEnoughExperience - }.orElse(false) + ServerNetworkingFactory.notify(player, NotificationType.Spent) + return true + } + return false } override fun skillUp(skill: Attribute, amount: Int, override: Boolean): Boolean { From 393c3383de4d983c684b2779317211cfc03517bb Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Sat, 12 Oct 2024 17:38:13 -0500 Subject: [PATCH 3/3] [chore/semver] update changelog, stage beta.10 --- CHANGELOG.md | 3 ++- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff006b26..3cfe4a51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ ## Changes 🌽 -- Removed an attribute function that was not meant to be present. \ No newline at end of file +- Made skill point increases separate to the actual attribute value. + - As for increases to skills like **Constitution** that come from somewhere else, it will be tacked on the right in square brackets. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 28c9b11f..10504d36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ parchment_version=1.20.1:2023.09.03 quilt_mappings_version=23 # Mod Properties -mod_version=4.0.0+1.20.1-beta.9 +mod_version=4.0.0+1.20.1-beta.10 maven_group=com.bibireden.playerex archives_base_name=playerex-directors-cut