Reading Entity names too early in MobModifierComponent / Incompatibility with Hexbound
Cypher121 opened this issue ยท 1 comments
Got a bug report about a crash involving Eldritch Mobs when /summon-ing one of my entities, looks like this:
java.lang.NullPointerException: Cannot invoke "coffee.cypher.hexbound.util.DataTrackerDelegate.getValue(net.minecraft.class_1297, kotlin.reflect.KProperty)" because "this.isAltModelEnabled$delegate" is null
at coffee.cypher.hexbound.feature.construct.entity.SpiderConstructEntity.isAltModelEnabled(SpiderConstructEntity.kt:43) ~[hexbound-0.1.0-beta.3+1.19.2.jar:?]
at coffee.cypher.hexbound.util.UtilKt.redirectSpiderLang(Util.kt:70) ~[hexbound-0.1.0-beta.3+1.19.2.jar:?]
at coffee.cypher.hexbound.feature.construct.entity.SpiderConstructEntity.method_23315(SpiderConstructEntity.kt:134) ~[hexbound-0.1.0-beta.3+1.19.2.jar:?]
at net.minecraft.class_1297.method_5477(class_1297.java:2476) ~[client-intermediary.jar:?]
at net.minecraft.class_1297.method_5476(class_1297.java:2719) ~[client-intermediary.jar:?]
at net.hyper_pigeon.eldritch_mobs.component.MobModifierComponent.<init>(MobModifierComponent.java:44) ~[eldritch-mobs-1.12.10.jar:?]
at dev.onyxstudios.cca._generated_.GeneratedComponentContainer_EntityImpl_class_1308_135614a3.<init>(Unknown Source) ~[?:?]
at dev.onyxstudios.cca._generated_.GeneratedContainerFactory_EntityImpl_class_1308_135614a3.createContainer(Unknown Source) ~[?:?]
at dev.onyxstudios.cca.internal.entity.CardinalEntityInternals.createEntityComponentContainer(CardinalEntityInternals.java:58) ~[cardinal-components-entity-5.0.2.jar-d23f46ae-afaf-4993-8664-1875d2a279eb-nested.jar:?]
at net.minecraft.class_1297.handler$zoo000$initDataTracker(class_1297.java:5616) ~[client-intermediary.jar:?]
The problem here is the attempt over here to read the entity's display name, while creating the component. CCA components are created before the entity is fully finished running its constructor, so the $delegate synthetic variable I use in my getDisplayName is not populated yet.
Ultimately entities given by CCA should be considered volatile when the constructor is running, cause their internal state is all messed up by CCA passing it around mid-constructor, so while I can band-aid it on my end, it'd be best for Eldritch Mobs to create the boss bar at a later point, so as not to depend on "enough" of the entity being constructed in time.
Also seems to be the cause of #76 where a different component is required for the display name, but wasn't added yet