Skip to content

Commit

Permalink
2.0.0+1.20.1 (release) (#33)
Browse files Browse the repository at this point in the history
* [chore] update `fabric.mod.json` to include all authors/contributors

* [ref] provide `MANAGER` directly in `reload`

* [fix] let identifier serializer throw exception when parsing fails

* [chore] Change to `workflow_dispatch`

* [partial-feat] Implement new AttributeOverrideProvider

* [partial-feat] Added ability to remove attribute overrides & def.tooltip

* [chore] Make `Validators` internal

* [feat] Make SearchAnchor & Ability to Add/Edit Overrides

* [ref] use `xor` for switching, remove shadow of id

* [chore&semver] update version & move to actions v3

* [chore] CL and small cleanup

* [feat] Incorporate Attribute Function V2

* [fix] Push attribute function buttons to first position

* [feat] Integrate EntityTypesProvider, remove old providers

* [fix] Fix component rendering

* [fix] Resolve problems with tooltips

* [feat] Add `ParsedTextBoxComponent`

* [ref] Refractored all field components, added parsing

* [fix] Allow adding of entity-types with default data

* [feat] Add the ability to disable/enable functions, update CL

* [chore] Adjust CL, make small refractoring change to AF provider

* [removal] Remove `DefaultAttributeFactory`

* [ref] Make `List<AttributeFunction>` into `Map` with identifier

* [fix] Fixed UI components not rendering with new links

* [feat] Introduce `EntityTypeEntry` and fallback

* [chore] update CL

* [fix] Force unknowns to have priority render

* [ref] Changed edit field and text box to be more agnostic

* [chore] comment clearing

* [fix] revert typing on `Endec.keyOf` extension

* [ref] Remove `RemoveButtonComponent`, add `ButtonComponents`

* [feat] added autocomplete for edit fields

* [feat] implement diminishing as it was intended...
  • Loading branch information
bibi-reden authored Oct 11, 2024
1 parent 8ac0aad commit 194d384
Show file tree
Hide file tree
Showing 41 changed files with 1,171 additions and 603 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/audit-pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: build/libs/
9 changes: 1 addition & 8 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
name: Deployment (J17)
on:
push:
branches-ignore:
- master
- "**/dev**"
- "**-dev"
- "**-dev**"
- dev
on: [workflow_dispatch]


jobs:
Expand Down
42 changes: 40 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
## Fixes 🍋
- Adjusted formatting of `Whole` formats to not go past two decimals.
## Overview
**There are breaking changes in this release. Ensure you back up your config(s) if possible. Mods relying on the beta version will have to be updated.**

*Welcome to the release of the new Data Attributes. This has taken a considerable amount of time to complete.*

*I am glad to have this opportunity to work on this project and be supported with the first ever public project I will personally release.*

## Additions 🍎
- No more needing to leave the UI to your config json~ you can do everything you need to do in the UI!
- Allowed easier control of the config menu, and added some new features.
- A `Reset` option to reset your targeted attribute, refreshing all its entries to start anew.
- A `Remove` option to remove the targeted entry of your choice.
- A `Edit` option to edit the identifier to target a different entry.
- A `Add` option to include new entries.
- You can also add into default entries.
- Added autocomplete that will appear while editing fields. This will show you currently registered entities and attributes when editing the respective id you want.
- Press [ENTER] to quickly grab the first entry on the autocomplete.
- Attribute components in configuration now will re-render in certain scenarios, allowing for a better experience with working with multiple attributes.
- Improved logic with entering fields, commit changes by pressing [Done], and [Reload] to refresh to the latest config.
- You can now actually use the search bar to look up the specific entries you wish to find.
- Translations should be compatible in the language you choose as well as the attribute id.
- e.g., looking up `playerex:luck`, or `Luck` should work.
- You can now enable/disable Attribute Functions.

## Changes 🌽
- **[BREAKING]** Changed mockup of config JSON.
- Config keys such as `"functions"/"overrides"/"entity_types": { ... }` have been replaced with `"entries": { ... }`.
- This retains parity with the data-pack format.
- **[BREAKING]** Changed `Map<Identifier, Double>` to `Map<Identifier, EntityTypeEntry>` for `EntityTypeData`.
- This also includes a `fallback` value that gets the default registered base value for the specific attribute under that entity.
- **[BREAKING]** Changed overall structure of config related class definitions. This will affect your config file considerably.
- **[BREAKING]** Removed `DefaultAttributeFactory`.
- **[BREAKING]** Changed `Map<Identifier, List<AttributeFunction>>` to `Map<Identifier, Map<Identifier, AttributeFunction>>`
- This existed to avoid an odd situation that does not exist anymore.
- 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.
- **[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).
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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+1.20.1-beta.13
mod_version=2.0.0+1.20.1
loader=fabric

# Mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected void onUpdate() {}

if (this.data_attributes$container != null) {
attribute.data_attributes$parentsMutable().forEach((parentAttribute, function) -> {
if (function.getBehavior() != StackingBehavior.Add) return;
if (!function.getEnabled() || function.getBehavior() != StackingBehavior.Add) return;

EntityAttributeInstance parentInstance = this.data_attributes$container.getCustomInstance((EntityAttribute) parentAttribute);
if (parentInstance == null) return;
Expand Down Expand Up @@ -145,7 +145,7 @@ protected void onUpdate() {}

if (this.data_attributes$container != null) {
attribute.data_attributes$parentsMutable().forEach((parentAttribute, function) -> {
if (function.getBehavior() != StackingBehavior.Multiply) return;
if (!function.getEnabled() || function.getBehavior() != StackingBehavior.Multiply) return;

EntityAttributeInstance parentInstance = this.data_attributes$container.getCustomInstance((EntityAttribute) parentAttribute);
if (parentInstance == null) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bibireden.data_attributes

import com.bibireden.data_attributes.api.DataAttributesAPI.serverManager
import com.bibireden.data_attributes.config.AttributeConfigManager
import com.bibireden.data_attributes.config.entry.DefaultAttributesReloadListener
import com.bibireden.data_attributes.config.models.DataAttributesConfig
Expand Down Expand Up @@ -72,12 +71,10 @@ class DataAttributes : ModInitializer {
fun reload(server: MinecraftServer) {
reloadConfigs()

val manager = serverManager
MANAGER.update()
MANAGER.nextUpdateFlag()

manager.update()
manager.nextUpdateFlag()

val buf = AttributeConfigManager.Packet.ENDEC.encodeFully({ ByteBufSerializer.of(PacketByteBufs.create()) }, manager.toPacket())
val buf = AttributeConfigManager.Packet.ENDEC.encodeFully({ ByteBufSerializer.of(PacketByteBufs.create()) }, MANAGER.toPacket())
PlayerLookup.all(server).forEach { player -> ServerPlayNetworking.send(player, NetworkingChannels.RELOAD, buf) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import net.minecraft.registry.Registries
import net.minecraft.util.Identifier
import java.util.*
import java.util.function.Supplier
import kotlin.jvm.optionals.getOrNull

/**
* Supplier classes to provide dynamic attribute references.
*/
class EntityAttributeSupplier(val id: Identifier) : Supplier<Optional<EntityAttribute>> {
override fun get() = Optional.ofNullable(Registries.ATTRIBUTE[this.id])

fun getOrNull() = Optional.ofNullable(Registries.ATTRIBUTE[this.id]).getOrNull()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +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

// CN: ((1.0 - v2) * (1.0 - m).pow((v - v2) / m)) - ((1.0 - k2) * (1.0 - m).pow((k - k2) / m))
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`()
val result = base + (((k - base) - v) * smoothness)
result
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 @@ -26,29 +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)
}


// 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)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.bibireden.data_attributes.api.parser

typealias Parser<I, O> = (I) -> O?
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.bibireden.data_attributes.config.entry.DefaultAttributesReloadListene
import com.bibireden.data_attributes.config.functions.AttributeFunction
import com.bibireden.data_attributes.config.models.OverridesConfigModel.AttributeOverride
import com.bibireden.data_attributes.data.EntityAttributeData
import com.bibireden.data_attributes.data.EntityTypeData
import com.bibireden.data_attributes.config.entities.EntityTypeData
import com.bibireden.data_attributes.endec.Endecs
import com.bibireden.data_attributes.ext.keyOf
import com.bibireden.data_attributes.mutable.MutableEntityAttribute
Expand All @@ -30,7 +30,7 @@ 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()) {
class AttributeConfigManager(var data: Data = Data(), private val handler: AttributeContainerHandler = AttributeContainerHandler()) {
var updateFlag: Int = 0

var defaults: DefaultAttributesReloadListener.Cache = DefaultAttributesReloadListener.Cache()
Expand All @@ -55,14 +55,14 @@ class AttributeConfigManager(var data: Data = Data(), val handler: AttributeCont
*/
data class Data(
var overrides: Map<Identifier, AttributeOverride> = mapOf(),
var functions: Map<Identifier, List<AttributeFunction>> = mapOf(),
var functions: Map<Identifier, Map<Identifier, AttributeFunction>> = mapOf(),
var entity_types: Map<Identifier, EntityTypeData> = mapOf()
)
{
companion object {
val ENDEC = StructEndecBuilder.of(
Endecs.IDENTIFIER.keyOf(AttributeOverride.ENDEC).fieldOf("overrides") { it.overrides },
Endecs.IDENTIFIER.keyOf(AttributeFunction.ENDEC.listOf()).fieldOf("functions") { it.functions },
Endecs.IDENTIFIER.keyOf(Endecs.IDENTIFIER.keyOf(AttributeFunction.ENDEC)).fieldOf("functions") { it.functions },
Endecs.IDENTIFIER.keyOf(EntityTypeData.ENDEC).fieldOf("entity_types") { it.entity_types },
::Data
)
Expand Down Expand Up @@ -93,7 +93,7 @@ class AttributeConfigManager(var data: Data = Data(), val handler: AttributeCont
get() = this.data.overrides

/** Currently applied [AttributeFunction]'s tied to the parent [EntityAttribute]'s [Identifier]. */
val functions: Map<Identifier, List<AttributeFunction>>
val functions: Map<Identifier, Map<Identifier, AttributeFunction>>
get() = this.data.functions

/** Currently applied [EntityTypeData] tied to an [EntityType]'s [Identifier]. */
Expand Down Expand Up @@ -179,7 +179,7 @@ class AttributeConfigManager(var data: Data = Data(), val handler: AttributeCont
}
}

private fun insertFunctions(store: Map<Identifier, List<AttributeFunction>>, data: MutableMap<Identifier, EntityAttributeData>) {
private fun insertFunctions(store: Map<Identifier, Map<Identifier, AttributeFunction>>, data: MutableMap<Identifier, EntityAttributeData>) {
for ((id, functions) in store) {
if (!Registries.ATTRIBUTE.containsId(id)) {
DataAttributes.LOGGER.warn("Function parent [$id] that was defined in config is not registered. This has been skipped.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.bibireden.data_attributes.config

import com.bibireden.data_attributes.config.AttributeConfigManager.Companion.ENTITY_TYPE_INSTANCES
import com.bibireden.data_attributes.config.AttributeConfigManager.Tuple
import com.bibireden.data_attributes.data.EntityTypeData
import com.bibireden.data_attributes.config.entities.EntityTypeData
import com.bibireden.data_attributes.mutable.MutableAttributeContainer
import com.bibireden.data_attributes.mutable.MutableDefaultAttributeContainer
import net.minecraft.entity.EntityType
Expand Down
Loading

0 comments on commit 194d384

Please sign in to comment.