diff --git a/gradle.properties b/gradle.properties index 5e32ec6..d2a2fd9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loom_version=1.7-SNAPSHOT minecraft_version=1.20.1 fabric_kotlin_version=1.11.0+kotlin.2.0.0 fabric_api_version=0.92.2+1.20.1 -mod_version=2.0.0-beta.5+1.20.1 +mod_version=2.0.0-beta.6+1.20.1 loader=fabric yarn_mappings=1.20.1+build.10 diff --git a/src/main/java/com/bibireden/data_attributes/api/attribute/IEntityAttribute.java b/src/main/java/com/bibireden/data_attributes/api/attribute/IEntityAttribute.java index 6a2660c..7633967 100644 --- a/src/main/java/com/bibireden/data_attributes/api/attribute/IEntityAttribute.java +++ b/src/main/java/com/bibireden/data_attributes/api/attribute/IEntityAttribute.java @@ -8,7 +8,7 @@ * * EntityAttribute's implement this through a mixin, and can be cast to this interface to get additional data added by Data Attributes. * - * @author CleverNucleus + * @author Bare Minimum Studios (B.M.S), CleverNucleus * */ public interface IEntityAttribute { diff --git a/src/main/java/com/bibireden/data_attributes/api/attribute/IEntityAttributeInstance.java b/src/main/java/com/bibireden/data_attributes/api/attribute/IEntityAttributeInstance.java index 7060566..7a51bb5 100644 --- a/src/main/java/com/bibireden/data_attributes/api/attribute/IEntityAttributeInstance.java +++ b/src/main/java/com/bibireden/data_attributes/api/attribute/IEntityAttributeInstance.java @@ -5,7 +5,7 @@ /** * * Access to an entity attribute instance. - * @author CleverNucleus + * @author Bare Minimum Studios (B.M.S), CleverNucleus * */ public interface IEntityAttributeInstance { diff --git a/src/main/java/com/bibireden/data_attributes/api/attribute/IItemEntityAttributeModifiers.java b/src/main/java/com/bibireden/data_attributes/api/attribute/IItemEntityAttributeModifiers.java index 08fd378..705cf34 100644 --- a/src/main/java/com/bibireden/data_attributes/api/attribute/IItemEntityAttributeModifiers.java +++ b/src/main/java/com/bibireden/data_attributes/api/attribute/IItemEntityAttributeModifiers.java @@ -11,7 +11,7 @@ /** * Implement this in your Item class. * - * @author CleverNucleus + * @author Bare Minimum Studios (B.M.S), CleverNucleus * */ public interface IItemEntityAttributeModifiers { diff --git a/src/main/java/com/bibireden/data_attributes/api/attribute/StackingBehavior.java b/src/main/java/com/bibireden/data_attributes/api/attribute/StackingBehavior.java index ae51e4c..b8afebf 100644 --- a/src/main/java/com/bibireden/data_attributes/api/attribute/StackingBehavior.java +++ b/src/main/java/com/bibireden/data_attributes/api/attribute/StackingBehavior.java @@ -1,39 +1,29 @@ package com.bibireden.data_attributes.api.attribute; /** + * Used to factor into {@link com.bibireden.data_attributes.config.functions.AttributeFunction}'s + * to determine what operation to use when calculating how their modifier(s) are applied. + *
* @since 1.4.0 - * @author CleverNucleus + * @author Bare Minimum Studios (B.M.S), CleverNucleus */ public enum StackingBehavior { - /** Addition of values as defined by the parent attribute. Equivalent of EntityAttributeModifier.Operation.ADDITION. */ - Add((byte)0), - /** Multiplication of parent attribute. Equivalent of EntityAttributeModifier.Operation.MULTIPLY_TOTAL. */ - Multiply((byte)1); - - private final byte id; - - StackingBehavior(final byte id) { - this.id = id; - } - - public static StackingBehavior of(final byte id) { - return switch(id) { - case 0 -> Add; - case 1 -> Multiply; - default -> Add; - }; - } + /** + * Addition of values as defined by the parent attribute. + * + * Equivalent to {@link net.minecraft.entity.attribute.EntityAttributeModifier.Operation#ADDITION}. + */ + Add, + /** + * Multiplication of parent attribute. + *
+ * Equivalent to {@link net.minecraft.entity.attribute.EntityAttributeModifier.Operation#MULTIPLY_TOTAL}.
+ */
+ Multiply;
public static StackingBehavior of(final String id) {
return id.equalsIgnoreCase("multiply") ? Multiply : Add;
}
-
- public byte id() {
- return this.id;
- }
-
- @Override
- public String toString() {
- return String.valueOf(this.id);
- }
+
+ public String getTranslationKey() { return "text.data_attributes.stackingBehavior." + this.name().toLowerCase(); }
}
diff --git a/src/main/kotlin/com/bibireden/data_attributes/api/attribute/StackingFormula.kt b/src/main/kotlin/com/bibireden/data_attributes/api/attribute/StackingFormula.kt
index 3d9c2d7..75dfd50 100644
--- a/src/main/kotlin/com/bibireden/data_attributes/api/attribute/StackingFormula.kt
+++ b/src/main/kotlin/com/bibireden/data_attributes/api/attribute/StackingFormula.kt
@@ -1,34 +1,17 @@
package com.bibireden.data_attributes.api.attribute
import io.wispforest.endec.Endec
-import net.minecraft.util.math.MathHelper
import kotlin.math.abs
-import kotlin.math.pow
// CN: ((1.0 - v2) * (1.0 - m).pow((v - v2) / m)) - ((1.0 - k2) * (1.0 - m).pow((k - k2) / m))
enum class StackingFormula(val function: (k: Double, k2: Double, v: Double, v2: Double, attribute: IEntityAttribute) -> Double) {
Flat({ k, _, v, _, _ -> k - v }),
Diminished({ k, k2, v, v2, attribute ->
- val min = attribute.`data_attributes$min`()
- val max = attribute.`data_attributes$max`()
-
- val k = k / 100
- val k2 = k2 / 100
- val v = v / 100
- val v2 = v2 / 100
-
- val s = MathHelper.clamp(attribute.`data_attributes$smoothness`(), 0.01, 1.0)
-
- val result1 = (1.0 - v2)
- val result2 = (1.0 - s).pow((v - v2) / s)
- val result3 = result1 * result2
-
- val result4 = (1.0 - k2)
- val result5 = (1.0 - s).pow((k - k2) / s)
- val result6 = (result4 * result5)
-
- (((result3-result6)) * (max-min)) - min
+ val base = (attribute as net.minecraft.entity.attribute.EntityAttribute).defaultValue
+ val smoothness = attribute.`data_attributes$smoothness`()
+ val result = base + (((k - base) - v) * smoothness)
+ result
});
companion object {
@@ -37,9 +20,34 @@ enum class StackingFormula(val function: (k: Double, k2: Double, v: Double, v2:
fun of(id: String) = if (id.equals("diminished", ignoreCase = true)) Diminished else Flat
}
+ val translationKey: String
+ get() = "text.data_attributes.stackingFormula.${this.name.lowercase()}"
+
fun max(current: Double, input: Double): Double = kotlin.math.max(current, abs(input))
fun stack(current: Double, input: Double): Double = current + abs(input)
fun result(k: Double, k2: Double, v: Double, v2: Double, attribute: IEntityAttribute): Double = this.function(k, k2, v, v2, attribute)
-}
\ No newline at end of file
+}
+
+
+// the solution?
+//val min = attribute.`data_attributes$min`()
+//val max = attribute.`data_attributes$max`()
+//
+//val k = k / 100
+//val k2 = k2 / 100
+//val v = v / 100
+//val v2 = v2 / 100
+//
+//val s = MathHelper.clamp(attribute.`data_attributes$smoothness`(), 0.01, 1.0)
+//
+//val result1 = (1.0 - v2)
+//val result2 = (1.0 - s).pow((v - v2) / s)
+//val result3 = result1 * result2
+//
+//val result4 = (1.0 - k2)
+//val result5 = (1.0 - s).pow((k - k2) / s)
+//val result6 = (result4 * result5)
+//
+//((((result3-result6)) * (max-min)) - min).round(2)
\ No newline at end of file
diff --git a/src/main/kotlin/com/bibireden/data_attributes/config/AttributeConfigManager.kt b/src/main/kotlin/com/bibireden/data_attributes/config/AttributeConfigManager.kt
index c8dffcd..24a6041 100644
--- a/src/main/kotlin/com/bibireden/data_attributes/config/AttributeConfigManager.kt
+++ b/src/main/kotlin/com/bibireden/data_attributes/config/AttributeConfigManager.kt
@@ -2,6 +2,7 @@ package com.bibireden.data_attributes.config
import com.bibireden.data_attributes.DataAttributes
import com.bibireden.data_attributes.api.EntityInstances
+import com.bibireden.data_attributes.api.attribute.IEntityAttribute
import com.bibireden.data_attributes.api.event.AttributesReloadedEvent
import com.bibireden.data_attributes.config.models.OverridesConfigModel.AttributeOverride
import com.bibireden.data_attributes.config.functions.AttributeFunction
@@ -27,7 +28,9 @@ import net.minecraft.util.Identifier
/**
* Used to manage config data, and contains an [AttributeContainerHandler] to build related [EntityTypeData].
*/
-class AttributeConfigManager(var data: Data = Data(), val handler: AttributeContainerHandler = AttributeContainerHandler(), var updateFlag: Int = 0) {
+class AttributeConfigManager(var data: Data = Data(), val handler: AttributeContainerHandler = AttributeContainerHandler()) {
+ var updateFlag: Int = 0
+
@JvmRecord
data class Tuple