Shadows-of-Fire / Apothic-Attributes

Attributes library for Minecraft, used by Apotheosis.
MIT License
7 stars 9 forks source link

If Attributes for an Entity are Modified as it is spawned, the game crashes #5

Closed AngellusMortis closed 8 months ago

AngellusMortis commented 8 months ago

Minecraft: 1.21.1 Forge: 47.2.1 Apothic Attributes: 1.1.4 Placebo: 8.3.7

Mod that can cause the issue: Chocobo Knights of the Crafting Table 1.0.16

Mod creator says they update the attribute just as it is spawned since the attributes can vary due to breeding.

java.lang.NullPointerException: Cannot invoke "net.minecraft.world.entity.LivingEntity.m_9236_()" because "this.owner" is null
    at net.minecraft.world.entity.ai.attributes.AttributeMap.handler$zke000$apoth_attrModifiedEvent(AttributeMap.java:546) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.ai.attributes.AttributeMap.m_22157_(AttributeMap.java) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.ai.attributes.AttributeInstance.m_22129_(AttributeInstance.java:91) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.ai.attributes.AttributeInstance.m_22102_(AttributeInstance.java:169) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.ai.attributes.AttributeSupplier.m_22250_(AttributeSupplier.java:51) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.ai.attributes.AttributeMap.m_22187_(AttributeMap.java:49) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at java.util.Map.computeIfAbsent(Map.java:1054) ~[?:?]
    at net.minecraft.world.entity.ai.attributes.AttributeMap.m_22146_(AttributeMap.java:49) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.LivingEntity.m_21051_(LivingEntity.java:1827) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at com.bladeandfeather.chocoboknights.entity.UtilEntityStats.refreshCreatureAttributes(UtilEntityStats.java:161) ~[ChocoboKnightsOfTheCraftingTableByBladeAndFeather-1.20.1-1.0.16.jar%23547!/:1.0.16]
    at com.bladeandfeather.chocoboknights.entity.EntityChocobo.m_21204_(EntityChocobo.java:234) ~[ChocoboKnightsOfTheCraftingTableByBladeAndFeather-1.20.1-1.0.16.jar%23547!/:1.0.16]
    at net.minecraft.world.entity.LivingEntity.m_21133_(LivingEntity.java:1835) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.LivingEntity.m_21233_(LivingEntity.java:1656) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.LivingEntity.<init>(LivingEntity.java:235) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.Mob.<init>(Mob.java:123) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.PathfinderMob.<init>(PathfinderMob.java:14) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.AgeableMob.<init>(AgeableMob.java:29) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.animal.Animal.<init>(Animal.java:40) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.TamableAnimal.<init>(TamableAnimal.java:28) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at com.bladeandfeather.chocoboknights.entity.EntityChocobo.<init>(EntityChocobo.java:286) ~[ChocoboKnightsOfTheCraftingTableByBladeAndFeather-1.20.1-1.0.16.jar%23547!/:1.0.16]
    at net.minecraft.world.entity.EntityType.m_20615_(EntityType.java:525) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.EntityType.m_262451_(EntityType.java:403) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.EntityType.m_262455_(EntityType.java:393) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.entity.EntityType.m_20592_(EntityType.java:361) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.world.item.SpawnEggItem.m_6225_(SpawnEggItem.java:85) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:585) ~[forge-1.20.1-47.2.1-universal.jar%23870!/:?]
    at net.minecraft.world.item.ItemStack.m_41661_(ItemStack.java:245) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.level.ServerPlayerGameMode.m_7179_(ServerPlayerGameMode.java:355) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.network.ServerGamePacketListenerImpl.m_6371_(ServerGamePacketListenerImpl.java:1057) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.network.protocol.game.ServerboundUseItemOnPacket.m_5797_(ServerboundUseItemOnPacket.java:34) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.network.protocol.game.ServerboundUseItemOnPacket.m_5797_(ServerboundUseItemOnPacket.java:8) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.network.protocol.PacketUtils.m_263899_(PacketUtils.java:22) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.TickTask.run(TickTask.java:18) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.util.thread.BlockableEventLoop.m_6367_(BlockableEventLoop.java:156) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.util.thread.ReentrantBlockableEventLoop.m_6367_(ReentrantBlockableEventLoop.java:23) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:770) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:161) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.util.thread.BlockableEventLoop.m_7245_(BlockableEventLoop.java:130) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.MinecraftServer.m_129961_(MinecraftServer.java:753) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.MinecraftServer.m_7245_(MinecraftServer.java:747) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.util.thread.BlockableEventLoop.m_18701_(BlockableEventLoop.java:139) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.MinecraftServer.m_130012_(MinecraftServer.java:733) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:665) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23865!/:?]
    at java.lang.Thread.run(Thread.java:833) ~[?:?]
Shadows-of-Fire commented 8 months ago

Unfortunately that mod is ARR, which means I will not make code changes to support it.

The code paths shown mean they are overriding this method:

public AttributeMap getAttributes() {
   return this.attributes;
}

This is a pure getter, and should never be modifying the map. This override is where the incompatibility comes in, as AA sets the owner at the end of the LivingEntity constructor, and they are overriding code in such a manner that triggers an attribute modification before the constructor exits (which is normally impossible).

If they need to mess with attributes, they should do so in their entity constructor, or during a load method. They should absolutely never be adjusting the attributes during the call to getAttributes, as it violates the contract that getAttributes is a simple field getter.

It is probably a trivial fix to move their attribute modification code to a more appropriate point, but they will have to figure that out on their own as they have chosen to make their mod closed source.