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(val livingEntity: Class, val value: T) @@ -82,6 +85,18 @@ class AttributeConfigManager(var data: Data = Data(), val handler: AttributeCont ) } + /** Currently applied [AttributeOverride]'s mapped with an [EntityAttribute]'s [Identifier]. */ + val overrides: Map + get() = this.data.overrides + + /** Currently applied [AttributeFunction]'s tied to the parent [EntityAttribute]'s [Identifier]. */ + val functions: Map> + get() = this.data.functions + + /** Currently applied [EntityTypeData] tied to an [EntityType]'s [Identifier]. */ + val entityTypes: Map + get() = this.data.entity_types + /** * Increments to the next flag, usually signaling an update from the manager. * @return [Int] The update flag's current value. @@ -120,15 +135,22 @@ class AttributeConfigManager(var data: Data = Data(), val handler: AttributeCont fun onDataUpdate() { val entityAttributeData = mutableMapOf() - for ((id, value) in this.data.overrides) { + for ((id, value) in this.overrides) { if (!Registries.ATTRIBUTE.containsId(id)) { DataAttributes.LOGGER.warn("Attribute [$id] that was targeted for override is not registered. This has been skipped.") continue } + val attribute = Registries.ATTRIBUTE[id]!! as IEntityAttribute + if (value.max.isNaN()) { + value.max = attribute.`data_attributes$max_fallback`() + } + if (value.min.isNaN()) { + value.min = attribute.`data_attributes$min_fallback`() + } entityAttributeData[id] = EntityAttributeData(value) } - for ((id, configs) in this.data.functions) { + for ((id, configs) in this.functions) { if (!Registries.ATTRIBUTE.containsId(id)) { DataAttributes.LOGGER.warn("Function parent [$id] that was defined in config is not registered. This has been skipped.") } @@ -145,11 +167,11 @@ class AttributeConfigManager(var data: Data = Data(), val handler: AttributeCont data.override(getAttribute(id)!!) // was already asserted to exist in L: 124 } - for ((identifier, attributeData) in entityAttributeData) { - attributeData.copy(Registries.ATTRIBUTE[identifier]!!) // was already asserted to exist in L: 124 + for ((identifier, data) in entityAttributeData) { + data.copy(Registries.ATTRIBUTE[identifier]!!) // was already asserted to exist in L: 124 } - this.handler.buildContainers(this.data.entity_types) + this.handler.buildContainers(this.entityTypes) AttributesReloadedEvent.EVENT.invoker().onReloadCompleted() } diff --git a/src/main/kotlin/com/bibireden/data_attributes/config/models/OverridesConfigModel.kt b/src/main/kotlin/com/bibireden/data_attributes/config/models/OverridesConfigModel.kt index b952871..a40975b 100644 --- a/src/main/kotlin/com/bibireden/data_attributes/config/models/OverridesConfigModel.kt +++ b/src/main/kotlin/com/bibireden/data_attributes/config/models/OverridesConfigModel.kt @@ -24,9 +24,9 @@ class OverridesConfigModel { @JvmField var enabled: Boolean = true, @JvmField - var min: Double = 0.0, + var min: Double = Double.NaN, @JvmField - var max: Double = 1000.0, + var max: Double = Double.NaN, @JvmField var smoothness: Double = 0.01, @JvmField diff --git a/src/main/kotlin/com/bibireden/data_attributes/config/providers/AttributeFunctionsProvider.kt b/src/main/kotlin/com/bibireden/data_attributes/config/providers/AttributeFunctionsProvider.kt index 6c93075..a8857a1 100644 --- a/src/main/kotlin/com/bibireden/data_attributes/config/providers/AttributeFunctionsProvider.kt +++ b/src/main/kotlin/com/bibireden/data_attributes/config/providers/AttributeFunctionsProvider.kt @@ -29,7 +29,7 @@ class AttributeFunctionsProvider(val option: Option) : CollapsibleFoldableContainer(Sizing.content(), Sizing.content(), attributeIdentifierToText(topID), true).also { ct -> ct.gap(15) if (isFunctionParentUnregistered) { - ct.tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid")) + ct.titleLayout().tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid")) } functions.forEachIndexed { index, function -> val isFunctionChildUnregistered = isAttributeUnregistered(function.id) @@ -37,7 +37,7 @@ class AttributeFunctionsProvider(val option: Option) : Containers.collapsible(Sizing.content(), Sizing.content(), attributeIdentifierToText(function.id), true).also { it.gap(8) if (isFunctionChildUnregistered) { - it.tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid")) + it.titleLayout().tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid")) } else { val attribute = Registries.ATTRIBUTE[function.id] diff --git a/src/main/kotlin/com/bibireden/data_attributes/config/providers/AttributeOverrideProvider.kt b/src/main/kotlin/com/bibireden/data_attributes/config/providers/AttributeOverrideProvider.kt index 66ddbaa..e4f6e4d 100644 --- a/src/main/kotlin/com/bibireden/data_attributes/config/providers/AttributeOverrideProvider.kt +++ b/src/main/kotlin/com/bibireden/data_attributes/config/providers/AttributeOverrideProvider.kt @@ -42,7 +42,7 @@ class AttributeOverrideProvider(val option: Option if (isOverrideInvalid) { - topContainer.tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid")) + topContainer.titleLayout().tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid")) } topContainer.child(Containers.horizontalFlow(Sizing.fill(100), Sizing.fixed(15)).also { hf -> diff --git a/src/main/kotlin/com/bibireden/data_attributes/ui/DataAttributesConfigScreen.kt b/src/main/kotlin/com/bibireden/data_attributes/ui/DataAttributesConfigScreen.kt index f2eff4e..284289e 100644 --- a/src/main/kotlin/com/bibireden/data_attributes/ui/DataAttributesConfigScreen.kt +++ b/src/main/kotlin/com/bibireden/data_attributes/ui/DataAttributesConfigScreen.kt @@ -50,7 +50,7 @@ class DataAttributesConfigScreen(val overrides: OverridesConfig, val functions: val optionPanel = rootComponent.childById(FlowLayout::class.java, "option-panel") - if (this.client?.world != null) rootComponent.surface(Surface.blur(.55F, 2F)) + if (this.client?.world != null) rootComponent.surface(Surface.VANILLA_TRANSLUCENT) val sections = LinkedHashMap() diff --git a/src/main/kotlin/com/bibireden/data_attributes/ui/components/CollapsibleFoldableContainer.kt b/src/main/kotlin/com/bibireden/data_attributes/ui/components/CollapsibleFoldableContainer.kt index e2f438e..4103b62 100644 --- a/src/main/kotlin/com/bibireden/data_attributes/ui/components/CollapsibleFoldableContainer.kt +++ b/src/main/kotlin/com/bibireden/data_attributes/ui/components/CollapsibleFoldableContainer.kt @@ -13,10 +13,10 @@ class CollapsibleFoldableContainer(horizontalSizing: Sizing, verticalSizing: Siz fun getFoldableText(): MutableText { return if (isFoldered) { - Text.translatable("ui.data_attributes.collapsiblefoldablecontainer.uncollapse_all") + Text.translatable("ui.data_attributes.cfc.uncollapse_all") } else { - Text.translatable("ui.data_attributes.collapsiblefoldablecontainer.collapse_all") + Text.translatable("ui.data_attributes.cfc.collapse_all") } } diff --git a/src/main/resources/assets/data_attributes/lang/en_us.json b/src/main/resources/assets/data_attributes/lang/en_us.json index c6bad82..36771e1 100644 --- a/src/main/resources/assets/data_attributes/lang/en_us.json +++ b/src/main/resources/assets/data_attributes/lang/en_us.json @@ -104,6 +104,12 @@ {"text": "when ready.", "italic": true, "color": "gray"} ], - "ui.data_attributes.collapsiblefoldablecontainer.collapse_all": "Collapse", - "ui.data_attributes.collapsiblefoldablecontainer.uncollapse_all": "Uncollapse" + "ui.data_attributes.cfc.collapse_all": "Collapse", + "ui.data_attributes.cfc.uncollapse_all": "Uncollapse", + + "text.data_attributes.stackingFormula.flat": "Flat", + "text.data_attributes.stackingFormula.diminished": "Diminished", + + "text.data_attributes.stackingBehavior.add": "Add", + "text.data_attributes.stackingBehavior.multiply": "Multiply" } \ No newline at end of file