Skip to content

Commit

Permalink
beta.4 (fix manager sync, add gets to API)
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Jul 23, 2024
1 parent 70d5cda commit b7c7bcd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
## Additions 💫
- Added in the API a way to fetch functions, entity-types, and overrides from an `EntityAttribute`.
## Changes ⚙️
- Addressed issue with the `DefaultAttributeFactory` continuing to attach extra config entries, causing unneeded duplications.
- Resolved synchronization issues with the config manager, which caused issues when running DataAttributes on a server instance and connecting from a client.
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.3+1.20.1
mod_version=2.0.0-beta.4+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 @@ -30,23 +30,23 @@ abstract class LivingEntityMixin {
@Inject(method = "<init>", at = @At("TAIL"))
private void data_attributes$init(EntityType<? extends LivingEntity> entityType, World world, CallbackInfo ci) {
LivingEntity entity = (LivingEntity)(Object)this;
this.attributes = DataAttributes.MANAGER.getContainer(entityType, entity);
this.data_attributes$update_flag = DataAttributes.MANAGER.getUpdateFlag();
this.attributes = DataAttributes.getManagerFromWorld(entity.getWorld()).getContainer(entityType, entity);
this.data_attributes$update_flag = DataAttributes.getManagerFromWorld(entity.getWorld()).getUpdateFlag();
}

@SuppressWarnings("UnreachableCode")
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;tickActiveItemStack()V"))
private void data_attributes$tick(CallbackInfo ci) {
AttributeConfigManager manager = DataAttributesClient.MANAGER;
LivingEntity entity = ((LivingEntity) (Object) this);
AttributeConfigManager manager = DataAttributes.getManagerFromWorld(entity.getWorld());
final int updateFlag = manager.getUpdateFlag();

if (this.data_attributes$update_flag != updateFlag) {
this.data_attributes$update_flag = updateFlag;

LivingEntity entity = ((LivingEntity) (Object) this);

@SuppressWarnings("unchecked")
AttributeContainer handledContainer = DataAttributes.MANAGER.getContainer((EntityType<? extends LivingEntity>) entity.getType(), entity);
AttributeContainer handledContainer = DataAttributes.getManagerFromWorld(entity.getWorld()).getContainer((EntityType<? extends LivingEntity>) entity.getType(), entity);

handledContainer.setFrom(this.getAttributes());
this.attributes = handledContainer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import net.minecraft.entity.LivingEntity
import net.minecraft.entity.attribute.EntityAttributes
import net.minecraft.registry.Registries
import net.minecraft.util.Identifier
import net.minecraft.world.World
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger

Expand Down Expand Up @@ -66,6 +67,10 @@ class DataAttributes : ModInitializer {
/** Creates an [Identifier] associated with the [MOD_ID]. */
fun id(str: String) = Identifier.of(MOD_ID, str)!!

/** Acquires the proper manager based on the world. */
@JvmStatic
fun getManagerFromWorld(world: World) = if (world.isClient) DataAttributesClient.MANAGER else MANAGER

/** Reload all the data-attributes configs at once. */
@JvmStatic
fun reloadConfigs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.bibireden.data_attributes.api

import com.bibireden.data_attributes.DataAttributes
import com.bibireden.data_attributes.config.functions.AttributeFunction
import com.bibireden.data_attributes.config.models.OverridesConfigModel
import com.bibireden.data_attributes.data.EntityTypeData
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.attribute.EntityAttribute
import net.minecraft.registry.Registries
import java.util.*
import java.util.function.Supplier

Expand Down Expand Up @@ -44,4 +49,19 @@ object DataAttributesAPI {
Optional.empty()
}
}

@JvmStatic
fun getOverride(attribute: EntityAttribute): OverridesConfigModel.AttributeOverride? {
return DataAttributes.OVERRIDES_CONFIG.overrides[Registries.ATTRIBUTE.getId(attribute)]
}

@JvmStatic
fun getFunctions(attribute: EntityAttribute): List<AttributeFunction>? {
return DataAttributes.FUNCTIONS_CONFIG.functions.data[Registries.ATTRIBUTE.getId(attribute)]
}

@JvmStatic
fun getEntityTypes(attribute: EntityAttribute): EntityTypeData? {
return DataAttributes.ENTITY_TYPES_CONFIG.entity_types[Registries.ATTRIBUTE.getId(attribute)]
}
}

0 comments on commit b7c7bcd

Please sign in to comment.