Skip to content

Commit

Permalink
Merge branch '1.20.1/dev' into 1.20.1/fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Oct 12, 2024
2 parents e1f4e50 + a72b196 commit 1a3afd5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 49 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
## Changes 🌽
- Removed an attribute function that was not meant to be present.
- 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.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -172,60 +170,58 @@ 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 {
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

this.addRefundablePoints(-amount)
this.addSkillPoints(amount)
this.set(skill, (value - amount).toInt())

ServerNetworkingFactory.notify(player, NotificationType.Refunded)
ServerNetworkingFactory.notify(player, NotificationType.Refunded)

true
}.orElse(false)
return true
}

val modifiers: Map<ResourceLocation, Double>
Expand Down

0 comments on commit 1a3afd5

Please sign in to comment.