Skip to content

Commit

Permalink
i heard third time's the charm (beta.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Jul 22, 2024
1 parent 9297c8d commit 70d5cda
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## Changes ⚙️
- Addressed issue with attribute initialization on `LivingEntity` instances.
- Addressed issue with the `DefaultAttributeFactory` continuing to attach extra config entries, causing unneeded duplications.
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.2+1.20.1
mod_version=2.0.0-beta.3+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 @@ -21,6 +21,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents
import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.attribute.EntityAttributes
import net.minecraft.registry.Registries
import net.minecraft.util.Identifier
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import net.minecraft.util.Identifier
* 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 {
@JvmStatic
/** 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()
Expand All @@ -21,24 +22,34 @@ object DefaultAttributeFactory {
DataAttributes.OVERRIDES_CONFIG.save()
}

@JvmStatic
/** 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()
val config = DataAttributes.FUNCTIONS_CONFIG
val current = config.functions.data.toMutableMap()
for ((id, af) in functions) {
val currentFunctions = current.getOrPut(id) { listOf() }.toMutableList()
currentFunctions.addAll(af)
// I made my own bed, now I have to sit in it for a bit...
af.forEach {
if (current[id]?.find { existing -> existing.id == it.id } == null) {
currentFunctions.add(it)
}
}
current[id] = currentFunctions
}
DataAttributes.FUNCTIONS_CONFIG.functions.data = current
DataAttributes.FUNCTIONS_CONFIG.save()
}

@JvmStatic
/** 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()
for ((id, type) in entityTypes) {
val types = current.getOrPut(id) { EntityTypeData() }.data.toMutableMap()
types.putAll(type.data)
type.data.forEach { (typeID, value) ->
if (!types.contains(typeID)) types[typeID] = value
}
current[id] = EntityTypeData(types)
}
DataAttributes.ENTITY_TYPES_CONFIG.entity_types = current
Expand Down

0 comments on commit 70d5cda

Please sign in to comment.