Data Attributes

Data Attributes

4M Downloads

Botania Attribute Crash

Balakay420 opened this issue ยท 6 comments

commented

MC 1.18.2
Fabric Loader 0.14.8
Fabric-api-0.56.1+1.18.2.jar
data-attributes-1.1.6.jar
Botania-1.18.2-433-FABRIC.jar
https://paste.ee/p/NFDbV

Anytime player takes damage from a mob, game crashes

commented

Hi there,
I'll look into it. Thank you for the alert.
Just as a side note, AttributeFix should not be run in conjunction with Data Attributes. Although it's likely not the cause in this case, the game can crash when they run together.

commented

Alright I'll remove it thank you!

Also, when I remove DataAttributes, I don't have the issue.

commented

Strangely, I can't seem to replicate it after updating architectury api

commented

Hi there,
Just thought I'd post an update on this issue, because it's interesting and because I'm stumped.

Initial testing shows that the issue is simply that the attribute botania:pixie_spawn_chance is being registered, but it is not being added to the player's attribute container. This means that when the attribute value is called on the player, the attribute is null and so an exception occurs. This is fine so far.

What is interesting is what the following lines of code provide (for context, this code is for debugging and is run when a dummy item is right clicked - Item#use):

EntityAttribute attribute = Registry.ATTRIBUTE.get(new Identifier("botania:pixie_spawn_chance"));
System.out.println("Is Attribute Null? " + (attribute == null)); // returns false. So far so good.

boolean exists1 = PlayerEntity.createPlayerAttributes().build().has(attribute);
System.out.println("Player has attribute? " + exists1); // returns true; So far so good.

boolean exists2 = DefaultAttributeRegistry.get(EntityType.PLAYER).has(attribute);
System.out.println("Registry has attribute? " + exists2); // returns false; Uh-oh.

I don't know what your literacy in java is, so I apologise if I'm mansplaining, but here's what the above tells me: the attribute is registered; the attribute is successfully added to the player's static attribute creation (namely, here); but the attribute does not exist in the DefaultAttributeRegistry. The reason I'm stumped is because this (1)

PlayerEntity.createPlayerAttributes().build()

contains the attribute, but this (2)

DefaultAttributeRegistry.get(EntityType.PLAYER)

does not. Even though (2) is dependent on (1) as seen here

private static final Map<EntityType<? extends LivingEntity>, DefaultAttributeContainer> DEFAULT_ATTRIBUTE_REGISTRY = ImmutableMap.builder()....put(EntityType.PLAYER, PlayerEntity.createPlayerAttributes().build())....build();

This is confusing because all of the aforementioned is vanilla/fabric. Data Attribute's doesn't touch any of that, it only relies on DefaultAttributeRegistry#get. So while I acknowledge that Data Attributes is likely the cause, a) because I have other reports of mod incompatibilities and b) because without Data Attributes it works fine - I'm not really sure how to fix this one yet. What I can do for now is make it so that it at least doesn't crash.

This post/update is long, but I'm putting it here for transparency and just in case someone can see what I at the moment cannot.

commented

I appreciate the response! It's a mystery to me also, I wish I could be of help but I know nothing about coding & I haven't had this issue since yesterday. I deleted attribute fix so maybe that was the issue. I also posted an issue on Botania's github.

commented

botania has fixed this issue, closing this