Skip to content

Commit

Permalink
beta.7
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Jul 29, 2024
1 parent ad163ac commit 1406ca8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
12 changes: 1 addition & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Implemented diminishing formula.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<Double> e = new AtomicReference<>(d);

for (EntityAttributeModifier modifier : this.getModifiersByOperation(EntityAttributeModifier.Operation.MULTIPLY_BASE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<IEntityAttribute, AttributeFunction> data_attributes$parentsMutable();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
});
Expand All @@ -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)
}


Expand Down

0 comments on commit 1406ca8

Please sign in to comment.