forked from CleverNucleus/data-attributes
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement alpha.8 (DefaultAttributeFactory) (#20)
- Loading branch information
1 parent
5cd62a9
commit 1ca077c
Showing
5 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
## Additions 💫 | ||
- Diminishing setting should be implemented. It works somewhat differently compared to the wiki, so it will require documentation which will be supplimented in the future. | ||
- To use Diminishing behavior, click on the **Flat** button to toggle between Diminishing behavior for an attribute. | ||
- Adjust the smoothness (previously increment value) to your liking. | ||
- Added the `DefaultAttributeFactory`, which can be used in mods to add extra defaults to the config. | ||
- Currently, it is limited to hard-code, | ||
- Added `EntityAttributeSupplier` to the mod again. | ||
- Its purpose is just to be a wrapper on lazily evaluated `EntityAttribute` values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/com/bibireden/data_attributes/api/attribute/EntityAttributeSupplier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.bibireden.data_attributes.api.attribute | ||
|
||
import net.minecraft.entity.attribute.EntityAttribute | ||
import net.minecraft.registry.Registries | ||
import net.minecraft.util.Identifier | ||
import java.util.function.Supplier | ||
|
||
/** | ||
* Supplier classes to provide dynamic attribute references. | ||
*/ | ||
class EntityAttributeSupplier(val id: Identifier) : Supplier<EntityAttribute?> { | ||
override fun get() = Registries.ATTRIBUTE[this.id] | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/com/bibireden/data_attributes/api/factory/DefaultAttributeFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.bibireden.data_attributes.api.factory | ||
|
||
import com.bibireden.data_attributes.DataAttributes | ||
import com.bibireden.data_attributes.config.functions.AttributeFunction | ||
import com.bibireden.data_attributes.config.models.OverridesConfigModel.AttributeOverride | ||
import com.bibireden.data_attributes.data.EntityTypeData | ||
import net.minecraft.util.Identifier | ||
|
||
/** | ||
* Meant to register attributes into the DataAttributes config primarily after it is initialized. | ||
* | ||
* This is useful for mods that wish to implement their own defaults, so they can be applied to the world. | ||
* Ensure that it is not done through static initialization, the config is not guaranteed to exist at that time. Instead, register afterward, such as on **mod initialization**. | ||
*/ | ||
object DefaultAttributeFactory { | ||
/** Registers default [AttributeOverride]'s to the config if they are not present currently within the config. */ | ||
fun registerOverrides(overrides: Map<Identifier, AttributeOverride>) { | ||
val current = DataAttributes.OVERRIDES_CONFIG.overrides.toMutableMap() | ||
overrides.forEach { (id, ao) -> current.computeIfAbsent(id) { ao } } | ||
DataAttributes.OVERRIDES_CONFIG.overrides = current | ||
DataAttributes.OVERRIDES_CONFIG.save() | ||
} | ||
|
||
/** Registers default [AttributeFunction]'s to the config if they are not present currently within the config. */ | ||
fun registerFunctions(functions: Map<Identifier, List<AttributeFunction>>) { | ||
val current = DataAttributes.FUNCTIONS_CONFIG.functions.data.toMutableMap() | ||
functions.forEach { (id, af) -> current.computeIfAbsent(id) { af } } | ||
DataAttributes.FUNCTIONS_CONFIG.functions.data = current | ||
DataAttributes.FUNCTIONS_CONFIG.save() | ||
} | ||
|
||
/** Registers default [EntityTypeData]'s to the config if they are not present currently within the config. */ | ||
fun registerEntityTypes(entityTypes: Map<Identifier, EntityTypeData>) { | ||
val current = DataAttributes.ENTITY_TYPES_CONFIG.entity_types.toMutableMap() | ||
entityTypes.forEach { (id, types) -> current.computeIfAbsent(id) { types } } | ||
DataAttributes.ENTITY_TYPES_CONFIG.entity_types = current | ||
DataAttributes.ENTITY_TYPES_CONFIG.save() | ||
} | ||
} |