Skip to content

Commit

Permalink
Resolve deps, fix concurrency issue, add more to screen
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Jul 23, 2024
1 parent 5b072f8 commit 5240c97
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ loom {
sourceSet sourceSets.client
}
}

}

fabricApi {
Expand All @@ -68,6 +67,7 @@ dependencies {

modImplementation "maven.modrinth:projectile-damage-attribute:${project.projectile_damage_attribute_version}"
modImplementation include("maven.modrinth:AdditionalEntityAttributes:${project.additional_entity_attributes_version}")
modImplementation include("maven.modrinth:ranged-weapon-api:${project.ranged_weapon_api_version}")

modImplementation include("io.wispforest:endec:${project.endec_version}")
modImplementation include("io.wispforest.endec:netty:${project.endec_version}")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ additional_entity_attributes_version=1.7.0+1.20.0
projectile_damage_attribute_version=3.2.2+1.20.1-fabric
all_the_trims_version=3.4.2
placeholder_api_version=2.1.1+1.20
ranged_weapon_api_version=1.1.0+1.20.1

opc_version=1.0.0+1.20.1-fabric
data_attributes_version=2.0.0-beta.3+1.20.1-fabric
Expand Down
31 changes: 28 additions & 3 deletions src/client/kotlin/com/bibireden/playerex/ui/PlayerEXScreen.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.bibireden.playerex.ui

import com.bibireden.data_attributes.DataAttributes
import com.bibireden.data_attributes.api.DataAttributesAPI
import com.bibireden.data_attributes.api.attribute.EntityAttributeSupplier
import com.bibireden.data_attributes.api.attribute.IEntityAttribute
import com.bibireden.data_attributes.api.attribute.StackingBehavior
import com.bibireden.playerex.PlayerEXClient
import com.bibireden.playerex.api.attribute.PlayerEXAttributes
import com.bibireden.playerex.components.PlayerEXComponents
Expand All @@ -25,6 +27,7 @@ import io.wispforest.owo.ui.core.ParentComponent
import io.wispforest.owo.ui.core.Positioning
import io.wispforest.owo.ui.core.Sizing
import net.minecraft.client.network.ClientPlayerEntity
import net.minecraft.client.resource.language.I18n
import net.minecraft.entity.attribute.EntityAttribute
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.registry.Registries
Expand All @@ -33,14 +36,17 @@ import net.minecraft.util.Colors
import net.minecraft.util.Formatting
import kotlin.reflect.KClass

private val StackingBehavior.symbol: String
get() = if (this == StackingBehavior.Add) "+" else "×"

// Transformers
fun <T : Component> ParentComponent.childById(clazz: KClass<T>, id: String) = this.childById(clazz.java, id)

/** Primary screen for the mod that brings everything intended together. */
class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, DataSource.asset(PlayerEXClient.MAIN_UI_SCREEN_ID)) {
private var currentPage = 0

private val pages: MutableList<MutableList<Component>> = AttributesMenuRegistry.get()
private var pages: MutableList<MutableList<Component>> = AttributesMenuRegistry.get()

private val playerComponent by lazy { PlayerEXComponents.PLAYER_DATA.get(this.client?.player!!) }

Expand Down Expand Up @@ -119,7 +125,26 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
// todo: migrate
private fun createAttributeComponent(attribute: EntityAttribute): Component {
return Containers.horizontalFlow(Sizing.fill(100), Sizing.fixed(18)).also {
it.child(Components.label(Text.translatable(attribute.translationKey)).sizing(Sizing.content(), Sizing.fill(100)))
it.child(Components.label(Text.translatable(attribute.translationKey)).sizing(Sizing.content(), Sizing.fill(100))
.also { label ->
// todo: allow data_attributes to have API funcs for obtaining this data.
val entries = DataAttributes.FUNCTIONS_CONFIG.functions.data[attribute.id]
if (!entries.isNullOrEmpty()) {
label.tooltip(Text.translatable("playerex.ui.attribute_functions").also { text ->
text.append("\n\n")
entries.forEach { function ->
EntityAttributeSupplier(function.id).get()?.translationKey?.let { key ->
text.append(Text.translatable(key).formatted(Formatting.AQUA))
}
text.append(Text.literal(" ${function.behavior.symbol}").formatted(Formatting.GREEN))
text.append(Text.literal("${function.value}"))
text.append(Text.literal(" (${DataAttributesAPI.getValue(EntityAttributeSupplier(function.id), this.client?.player!!).orElse(0.0)})\n").formatted(Formatting.GRAY))
}
text.formatted(Formatting.ITALIC)
})
}
}.id("${attribute.id}:label")
)
it.child(Components.label(attributeLabel(attribute, this.client?.player!!)).id("${attribute.id}:current_level"))
it.child(
Containers.horizontalFlow(Sizing.fill(50), Sizing.fill(100)).also {
Expand Down Expand Up @@ -168,7 +193,7 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
val content = rootComponent.childById(FlowLayout::class, "content")!!
val footer = rootComponent.childById(FlowLayout::class, "footer")!!

pages.addAll(mutableListOf(temporarySupplyAttributePage()))
pages = mutableListOf(temporarySupplyAttributePage())

this.onLevelUpdated()
this.onAttributesUpdated()
Expand Down
4 changes: 2 additions & 2 deletions src/client/resources/assets/playerex/owo_ui/main_ui_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<flow-layout direction="horizontal">
<children>
<label>
<text translate="false">⚑ PlayerEX • Attributes Screen</text>
<text translate="false">⚑ PlayerEX • Leveling Screen</text>
<vertical-text-alignment>center</vertical-text-alignment>
<positioning type="relative">0,50</positioning>
</label>
Expand All @@ -20,7 +20,7 @@
<flow-layout direction="ltr-text-flow" id="points_available_window">
<children>
<label id="points_available"><text>0</text></label>
<label><text>POINTS AVAILABLE</text></label>
<label><text>POINT(S) AVAILABLE</text></label>
</children>

<gap>5</gap>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package com.bibireden.playerex.api.attribute
import com.bibireden.data_attributes.api.attribute.StackingBehavior
import com.bibireden.data_attributes.config.functions.AttributeFunction
import com.bibireden.data_attributes.data.EntityTypeData
import com.bibireden.playerex.PlayerEX
import com.bibireden.playerex.ext.id
import net.fabricmc.loader.api.FabricLoader
import de.dafuqs.additionalentityattributes.AdditionalEntityAttributes
import net.fabric_extras.ranged_weapon.api.EntityAttributes_RangedWeapon
import net.minecraft.entity.attribute.EntityAttributes
import net.minecraft.util.Identifier
import net.projectile_damage.ProjectileDamageMod

object DefaultAttributeImpl {
val FUNCTIONS: Map<Identifier, List<AttributeFunction>> = mapOf(
Expand All @@ -17,39 +18,43 @@ object DefaultAttributeImpl {
AttributeFunction(PlayerEXAttributes.POISON_RESISTANCE.id, StackingBehavior.Add, 0.1),
AttributeFunction(PlayerEXAttributes.FREEZE_RESISTANCE.id, StackingBehavior.Add, 0.1),
AttributeFunction(PlayerEXAttributes.LIGHTNING_RESISTANCE.id, StackingBehavior.Add, 0.1),
// todo: add additionalentityattributes as a modImplementation, making it mandatory.
AttributeFunction(Identifier.of("additionalentityattributes", "generic.magic_protection")!!, StackingBehavior.Add, 0.25),
AttributeFunction(Identifier.of("additionalentityattributes", "generic.lung_capacity")!!, StackingBehavior.Add, 0.25)
AttributeFunction(AdditionalEntityAttributes.MAGIC_PROTECTION.id, StackingBehavior.Add, 0.25),
AttributeFunction(AdditionalEntityAttributes.LUNG_CAPACITY.id, StackingBehavior.Add, 0.25)
),
PlayerEXAttributes.STRENGTH.id to listOf(
AttributeFunction(EntityAttributes.GENERIC_ATTACK_DAMAGE.id, StackingBehavior.Multiply, 0.02),
AttributeFunction(EntityAttributes.GENERIC_ATTACK_DAMAGE.id, StackingBehavior.Add, 0.02),
AttributeFunction(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE.id, StackingBehavior.Add, 0.1),
AttributeFunction(PlayerEXAttributes.MELEE_CRIT_DAMAGE.id, StackingBehavior.Multiply, 0.05),
AttributeFunction(PlayerEXAttributes.MELEE_CRIT_DAMAGE.id, StackingBehavior.Add, 0.05),
AttributeFunction(PlayerEXAttributes.BREAKING_SPEED.id, StackingBehavior.Add, 0.01),
),
PlayerEXAttributes.DEXTERITY.id to listOf(
AttributeFunction(EntityAttributes.GENERIC_ATTACK_SPEED.id, StackingBehavior.Multiply, 0.01),
AttributeFunction(PlayerEXAttributes.RANGED_DAMAGE.id, StackingBehavior.Multiply, 0.02),
AttributeFunction(PlayerEXAttributes.RANGED_CRITICAL_DAMAGE.id, StackingBehavior.Multiply, 0.05),
// AttributeFunction(.id, StackingBehavior.Multiply, 0.05), idk what or where draw speed is
AttributeFunction(EntityAttributes.GENERIC_ATTACK_SPEED.id, StackingBehavior.Add, 0.01),
AttributeFunction(PlayerEXAttributes.RANGED_DAMAGE.id, StackingBehavior.Add, 0.02),
AttributeFunction(PlayerEXAttributes.RANGED_CRITICAL_DAMAGE.id, StackingBehavior.Add, 0.05),
AttributeFunction(EntityAttributes_RangedWeapon.HASTE.id, StackingBehavior.Add, 0.05),
AttributeFunction(PlayerEXAttributes.FIRE_RESISTANCE.id, StackingBehavior.Add, 0.1),
),
PlayerEXAttributes.INTELLIGENCE.id to listOf(
// AttributeFunction(.id, StackingBehavior.Multiply, 0.05), idk what or where spell haste is.
// couulldd supply thru wizardex
// what is dropped experience
AttributeFunction(AdditionalEntityAttributes.DROPPED_EXPERIENCE.id, StackingBehavior.Add, 0.01),
AttributeFunction(PlayerEXAttributes.WITHER_RESISTANCE.id, StackingBehavior.Add, 0.1),
AttributeFunction(PlayerEXAttributes.HEAL_AMPLIFICATION.id, StackingBehavior.Multiply, 0.05),
AttributeFunction(PlayerEXAttributes.HEAL_AMPLIFICATION.id, StackingBehavior.Add, 0.05),
AttributeFunction(PlayerEXAttributes.HEALTH_REGENERATION.id, StackingBehavior.Add, 0.01),
),
PlayerEXAttributes.LUCKINESS.id to listOf(
AttributeFunction(PlayerEXAttributes.MELEE_CRIT_CHANCE.id, StackingBehavior.Multiply, 0.02),
AttributeFunction(PlayerEXAttributes.RANGED_CRITICAL_CHANCE.id, StackingBehavior.Multiply, 0.02),
AttributeFunction(PlayerEXAttributes.MELEE_CRIT_CHANCE.id, StackingBehavior.Add, 0.02),
AttributeFunction(PlayerEXAttributes.RANGED_CRITICAL_CHANCE.id, StackingBehavior.Add, 0.02),
// cannot find spell crit chance atm, maybe a wizard thing
// loot table chance?? wh-
AttributeFunction(PlayerEXAttributes.MELEE_CRIT_CHANCE.id, StackingBehavior.Add, 0.01),
AttributeFunction(EntityAttributes.GENERIC_LUCK.id, StackingBehavior.Add, 0.05),
AttributeFunction(PlayerEXAttributes.EVASION.id, StackingBehavior.Multiply, 0.01),
AttributeFunction(PlayerEXAttributes.EVASION.id, StackingBehavior.Add, 0.01),
),
PlayerEXAttributes.FOCUS.id to listOf(
AttributeFunction(PlayerEXAttributes.HEALTH_REGENERATION.id, StackingBehavior.Add, 0.01),
AttributeFunction(PlayerEXAttributes.HEAL_AMPLIFICATION.id, StackingBehavior.Add, 0.05),
AttributeFunction(PlayerEXAttributes.FREEZE_RESISTANCE.id, StackingBehavior.Add, 0.1),
AttributeFunction(PlayerEXAttributes.LIGHTNING_RESISTANCE.id, StackingBehavior.Add, 0.1),
AttributeFunction(PlayerEXAttributes.FIRE_RESISTANCE.id, StackingBehavior.Add, 0.1),
)
)
val ENTITY_TYPES: Map<Identifier, EntityTypeData> = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent
import dev.onyxstudios.cca.api.v3.component.sync.ComponentPacketWriter
import io.wispforest.endec.Endec
import io.wispforest.endec.impl.StructEndecBuilder
import io.wispforest.owo.ui.component.ButtonComponent
import io.wispforest.owo.ui.component.Components
import io.wispforest.owo.ui.core.Component
import net.minecraft.entity.attribute.EntityAttribute
import net.minecraft.entity.attribute.EntityAttributeInstance
import net.minecraft.entity.attribute.EntityAttributeModifier
Expand All @@ -28,6 +31,7 @@ import net.minecraft.nbt.NbtCompound
import net.minecraft.network.PacketByteBuf
import net.minecraft.registry.Registries
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import net.minecraft.util.math.MathHelper
import kotlin.math.round
Expand Down Expand Up @@ -131,17 +135,19 @@ class PlayerDataComponent(

val partition = if (percent == 0) 0.0 else percent / 100.0

val kept = mutableMapOf<Identifier, Double>()
for ((id, value) in this.modifiers) {
if (partition == 0.0) {
this.tryRemove(id)
this._modifiers.remove(id)
}
else {
val retained = value * partition
if (!this.trySet(id, retained)) continue
kept[id] = value
}
}

this._modifiers = kept
this._refundablePoints = round(this._refundablePoints * partition).toInt()
this._skillPoints = round(this._skillPoints * partition).toInt()
this.isLevelUpNotified = false
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/playerex/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

"playerex.ui.category.primary_attributes": "Attributes",

"playerex.ui.attribute_functions": [ {"text": "❤ Attribute Function(s)", "color": "#F6CB3B"} ],

"playerex.ui.current_level": [
{"text": "", "color": "#F6CB3B"},
{"text": "Level: ", "color": "white"},
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"minecraft": "~1.20.1",
"java": ">=17",
"fabric-api": "*",
"fabric-language-kotlin": ">=1.10.19+kotlin.1.9.23"
"fabric-language-kotlin": ">=1.10.19+kotlin.1.9.23",
"projectile_damage": ">=3.2.2+1.20.1-fabric"
},
"custom": {
"cardinal-components": [
Expand All @@ -64,7 +65,9 @@
"dependencies": [
"[email protected]+1.20.1(required){modrinth:P7dR8mSH}{curseforge:306612}#(ignore:github)",
"[email protected]+kotlin.1.8.22(required){modrinth:Ha28R6CL}{curseforge:308769}#(ignore:github)",
"[email protected](required){modrinth:ccKDOlHs}{curseforge:532610}#(ignore:github)"
"[email protected](required){modrinth:ccKDOlHs}{curseforge:532610}#(ignore:github)",
"[email protected]+1.20.1(embedded){modrinth:AqaIIO6D}{curseforge:962162}#(ignore:github)",
"[email protected](embedded){modrinth:K01OU20C}{curseforge:318449}#(ignore:github)"
]
}
}
Expand Down

0 comments on commit 5240c97

Please sign in to comment.