From 1406ca87aba1b8ee60e53e9cdf7b8add5bcf0dd2 Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Mon, 29 Jul 2024 17:59:22 -0500 Subject: [PATCH] beta.7 --- CHANGELOG.md | 12 +----------- gradle.properties | 2 +- .../mixin/EntityAttributeInstanceMixin.java | 4 ++-- .../data_attributes/mixin/EntityAttributeMixin.java | 5 +++-- .../mutable/MutableEntityAttribute.java | 3 ++- .../data_attributes/api/attribute/StackingFormula.kt | 11 ++++++----- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e43138..6b17a89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,3 @@ ## Additions 💫 -### API -- Added `getManager` which decides the proper AttributeConfigManager via a world instance. -- Added `clientManager` & `serverManager` respectively, which are self-explanatory. -## Changes ⚙️ -- Cleaned up codebase, adjusting certain logic. -- Updated Endec to match with wispforest's uploaded versions, and resolved issues with reading/writing Endec's that could cause a fatal exception. -- Updated `EntityAttributeSupplier` (again). -## Removals -- Removed `ConfigDefaults`. -- Removed the ability to access config through functions in the API. -- Removed an attribute modified event that changed health. This should be optionally handled in a workspace that implements the API instead. \ No newline at end of file +Implemented diminishing formula. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index d2a2fd9..61b2c3d 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.6+1.20.1 +mod_version=2.0.0-beta.7+1.20.1 loader=fabric yarn_mappings=1.20.1+build.10 diff --git a/src/main/java/com/bibireden/data_attributes/mixin/EntityAttributeInstanceMixin.java b/src/main/java/com/bibireden/data_attributes/mixin/EntityAttributeInstanceMixin.java index afed342..a066200 100644 --- a/src/main/java/com/bibireden/data_attributes/mixin/EntityAttributeInstanceMixin.java +++ b/src/main/java/com/bibireden/data_attributes/mixin/EntityAttributeInstanceMixin.java @@ -81,6 +81,7 @@ protected void onUpdate() {} return attribute != null ? attribute : original; } + @SuppressWarnings("UnreachableCode") @ModifyReturnValue(method = "computeValue", at = @At("RETURN")) private double data_attributes$computeValue(double original) { MutableEntityAttribute attribute = (MutableEntityAttribute) this.getAttribute(); @@ -133,8 +134,7 @@ protected void onUpdate() {} }); } - - double d = attribute.data_attributes$sum(k.get(), k2, v.get(), v2); + double d = attribute.data_attributes$sum(k.get(), k2, v.get(), v2, (EntityAttributeInstance) (Object) this); AtomicReference e = new AtomicReference<>(d); for (EntityAttributeModifier modifier : this.getModifiersByOperation(EntityAttributeModifier.Operation.MULTIPLY_BASE)) { diff --git a/src/main/java/com/bibireden/data_attributes/mixin/EntityAttributeMixin.java b/src/main/java/com/bibireden/data_attributes/mixin/EntityAttributeMixin.java index d53eb73..a70761f 100644 --- a/src/main/java/com/bibireden/data_attributes/mixin/EntityAttributeMixin.java +++ b/src/main/java/com/bibireden/data_attributes/mixin/EntityAttributeMixin.java @@ -5,6 +5,7 @@ import com.bibireden.data_attributes.config.models.OverridesConfigModel; import com.bibireden.data_attributes.config.functions.AttributeFunction; import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import net.minecraft.entity.attribute.EntityAttributeInstance; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -94,8 +95,8 @@ abstract class EntityAttributeMixin implements MutableEntityAttribute { } @Override - public double data_attributes$sum(final double k, final double k2, final double v, final double v2) { - return this.data_attributes$formula.result(k, k2, v, v2, this); + public double data_attributes$sum(final double k, final double k2, final double v, final double v2, EntityAttributeInstance instance) { + return this.data_attributes$formula.result(k, k2, v, v2, instance); } @Override diff --git a/src/main/java/com/bibireden/data_attributes/mutable/MutableEntityAttribute.java b/src/main/java/com/bibireden/data_attributes/mutable/MutableEntityAttribute.java index 6fe2783..cde0bb1 100644 --- a/src/main/java/com/bibireden/data_attributes/mutable/MutableEntityAttribute.java +++ b/src/main/java/com/bibireden/data_attributes/mutable/MutableEntityAttribute.java @@ -6,6 +6,7 @@ import com.bibireden.data_attributes.api.attribute.StackingFormula; import com.bibireden.data_attributes.config.models.OverridesConfigModel; import com.bibireden.data_attributes.config.functions.AttributeFunction; +import net.minecraft.entity.attribute.EntityAttributeInstance; /** * Extends the {@link net.minecraft.entity.attribute.EntityAttribute} class @@ -39,7 +40,7 @@ static boolean contains(MutableEntityAttribute lhs, MutableEntityAttribute rhs) * By including a secondary pair of variables, * it allows for the modeling of more complex scenarios, such as negative modifiers. */ - double data_attributes$sum(final double k, final double k2, final double v, final double v2); + double data_attributes$sum(final double k, final double k2, final double v, final double v2, EntityAttributeInstance instance); /** Returns a mutable map of parent entity attributes with associated functions. */ Map data_attributes$parentsMutable(); 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 75dfd50..c971c3d 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,15 +1,16 @@ package com.bibireden.data_attributes.api.attribute import io.wispforest.endec.Endec +import net.minecraft.entity.attribute.EntityAttributeInstance import kotlin.math.abs // 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) { +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, attribute -> - val base = (attribute as net.minecraft.entity.attribute.EntityAttribute).defaultValue - val smoothness = attribute.`data_attributes$smoothness`() + Diminished({ k, k2, v, v2, instance -> + val base = instance.baseValue + val smoothness = (instance.attribute as IEntityAttribute).`data_attributes$smoothness`() val result = base + (((k - base) - v) * smoothness) result }); @@ -27,7 +28,7 @@ enum class StackingFormula(val function: (k: Double, k2: Double, v: Double, v2: 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) + fun result(k: Double, k2: Double, v: Double, v2: Double, instance: EntityAttributeInstance): Double = this.function(k, k2, v, v2, instance) }