Skip to content

Commit

Permalink
[feat] implement diminishing as it was intended...
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Oct 11, 2024
1 parent cb45ccf commit 8a21faf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
- Made some changes to certain logic internally and micro-optimizations.
- Fixed CTD issues with editing function values.
- Separated config entries from defaults using color coding & tooltips.
- Integrated diminishing returns as intended.
- **[BREAKING]** Integrated diminishing returns as intended.
- You must keep and/or target attribute min/max ranges between -1 & 1.
- It is how it usually worked in the original DataAttributes, as unfortunately, a solution to implement diminishing returns on all attributes was not possible (at this time).
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package com.bibireden.data_attributes.api.attribute

import io.wispforest.endec.Endec
import net.minecraft.entity.attribute.EntityAttributeInstance
import net.minecraft.util.math.MathHelper
import kotlin.math.abs
import kotlin.math.pow

enum class StackingFormula(val function: (k: Double, k2: Double, v: Double, v2: Double, instance: EntityAttributeInstance) -> Double) {
Flat({ k, _, v, _, _ -> k - v }),
Diminished({ k, k2, v, v2, instance ->
val base = instance.baseValue
val smoothness = (instance.attribute as IEntityAttribute).`data_attributes$smoothness`()
base + (((k - base) - v) * smoothness)
val s = (instance.attribute as IEntityAttribute).`data_attributes$smoothness`()
((1.0 - v2) * (1.0 - s).pow((v - v2) / s)) - ((1.0 - k2) * (1.0 - s).pow((k - k2) / s))
});

companion object {
Expand All @@ -23,7 +24,13 @@ enum class StackingFormula(val function: (k: Double, k2: Double, v: Double, v2:

fun max(current: Double, input: Double): Double = kotlin.math.max(current, abs(input))

fun stack(current: Double, input: Double): Double = current + abs(input)
fun stack(current: Double, input: Double): Double {
var final = input
if (this == Diminished) {
final = MathHelper.clamp(final, -1.0, 1.0)
}
return current + abs(final)
}

fun result(k: Double, k2: Double, v: Double, v2: Double, instance: EntityAttributeInstance): Double = this.function(k, k2, v, v2, instance)
}

0 comments on commit 8a21faf

Please sign in to comment.