From 2bce0eae7cbc2f18b38a0eeb7ebfc19be0283328 Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Mon, 19 Aug 2024 07:40:15 -0500 Subject: [PATCH] Fix old -> new data issue, resolve some functions (#42) * [fix] adjust spell power's haste properly * [fix] change workflow to apply only on source code changes * [fix] (connector) resolve issue where old player data failed to transfer * Make `register` marked internal * [fix] resolve license * [semver] update version to beta.4 * [chore] update changelog * [revert] drop restriction --- CHANGELOG.md | 3 ++- LICENSE | 4 ---- gradle.properties | 2 +- .../playerex/api/attribute/PlayerEXAttributes.kt | 2 ++ .../playerex/components/player/PlayerDataComponent.kt | 10 +++++----- .../com/bibireden/playerex/factory/EventFactory.kt | 10 +++++++++- .../data/playerex/data_attributes/functions/stock.json | 2 +- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b036af1e..a36e27d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ ## Changes 🌽 -- Fixed yet another potential `NullPointerException` when registering a modded menu. \ No newline at end of file +- Reconciled connector based issue where old player data did not transfer over to a new player. +- Updated the modded datapack to apply some attributes properly to scale. \ No newline at end of file diff --git a/LICENSE b/LICENSE index 5eb64a68..8e5c953c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,7 @@ MIT License Copyright (c) 2022 CleverNucleus -<<<<<<< HEAD -Copyright (c) 2024 MerryweatherLost -======= Copyright (c) 2024 Bare Minimum Studios ->>>>>>> 4.0.0+1.20.1 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/gradle.properties b/gradle.properties index ff0d05fd..887dfa92 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.3 +mod_version=4.0.0+1.20.1-beta.4 maven_group=com.bibireden.playerex archives_base_name=playerex-directors-cut diff --git a/src/main/kotlin/com/bibireden/playerex/api/attribute/PlayerEXAttributes.kt b/src/main/kotlin/com/bibireden/playerex/api/attribute/PlayerEXAttributes.kt index b31236ef..8c7415d6 100644 --- a/src/main/kotlin/com/bibireden/playerex/api/attribute/PlayerEXAttributes.kt +++ b/src/main/kotlin/com/bibireden/playerex/api/attribute/PlayerEXAttributes.kt @@ -6,6 +6,7 @@ import net.minecraft.core.Registry import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.resources.ResourceLocation import net.minecraft.world.entity.ai.attributes.RangedAttribute +import org.jetbrains.annotations.ApiStatus object PlayerEXAttributes { @JvmField @@ -74,6 +75,7 @@ object PlayerEXAttributes { @JvmField val RANGED_CRITICAL_DAMAGE = register("ranged_crit_damage", 0.0, 0.0, 1_000_000.0) + @ApiStatus.Internal fun register(path: String, base: Double, min: Double, max: Double): RangedAttribute { val attribute = RangedAttribute("attribute.name.${PlayerEX.MOD_ID}.$path", base, min, max) return Registry.register(BuiltInRegistries.ATTRIBUTE, ResourceLocation.tryBuild(PlayerEX.MOD_ID, path)!!, attribute) 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 562abf68..dca75348 100644 --- a/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt +++ b/src/main/kotlin/com/bibireden/playerex/components/player/PlayerDataComponent.kt @@ -97,9 +97,7 @@ class PlayerDataComponent( * */ private fun tryRemove(key: ResourceLocation): Boolean { return this.getInstance(key)?.let { (instance, isModifierPresent) -> - if (isModifierPresent) { - instance.removeModifier(PlayerEXModifiers.UUID) - } + if (isModifierPresent) instance.removeModifier(PlayerEXModifiers.UUID) } != null } @@ -127,7 +125,7 @@ class PlayerDataComponent( } override fun reset(percent: Int) { - val partition = if (percent == 0) 0.0 else percent / 100.0 + val partition = percent / 100.0 val kept = mutableMapOf() for ((id, value) in this.modifiers) { @@ -136,7 +134,9 @@ class PlayerDataComponent( } else { val retained = value * partition - if (!this.trySet(id, retained)) continue + if (!this.trySet(id, retained)) { + continue + } kept[id] = retained } } diff --git a/src/main/kotlin/com/bibireden/playerex/factory/EventFactory.kt b/src/main/kotlin/com/bibireden/playerex/factory/EventFactory.kt index 7c03ff1c..66efceb3 100644 --- a/src/main/kotlin/com/bibireden/playerex/factory/EventFactory.kt +++ b/src/main/kotlin/com/bibireden/playerex/factory/EventFactory.kt @@ -3,8 +3,10 @@ package com.bibireden.playerex.factory import com.bibireden.data_attributes.api.DataAttributesAPI import com.bibireden.playerex.PlayerEX import com.bibireden.playerex.api.attribute.PlayerEXAttributes +import com.bibireden.playerex.components.player.PlayerDataComponent import com.bibireden.playerex.ext.component import com.bibireden.playerex.registry.DamageModificationRegistry +import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.server.level.ServerPlayer import net.minecraft.world.damagesource.DamageSource import net.minecraft.world.effect.MobEffects @@ -16,7 +18,13 @@ import net.minecraft.world.entity.projectile.AbstractArrow object EventFactory { fun reset(oldPlayer: ServerPlayer, newPlayer: ServerPlayer, isAlive: Boolean) { - newPlayer.component.reset(if (PlayerEX.CONFIG.resetOnDeath) 0 else 100) + val factor = if (PlayerEX.CONFIG.resetOnDeath) 0 else 100 + // attempt reconciliation + (oldPlayer.component as PlayerDataComponent).modifiers.forEach { (rl, value) -> + val attr = BuiltInRegistries.ATTRIBUTE[rl] ?: return@forEach + newPlayer.component.set(attr, value.toInt()) + } + newPlayer.component.reset(factor) } fun healed(entity: LivingEntity, amount: Float): Float diff --git a/src/main/resources/data/playerex/data_attributes/functions/stock.json b/src/main/resources/data/playerex/data_attributes/functions/stock.json index 3f786cbf..b401cd70 100644 --- a/src/main/resources/data/playerex/data_attributes/functions/stock.json +++ b/src/main/resources/data/playerex/data_attributes/functions/stock.json @@ -90,7 +90,7 @@ { "id": "spell_power:haste", "behavior": "Add", - "value": 0.002 + "value": 2 } ], "playerex:focus": [