aurilisdev / Electrodynamics

Electrodynamics is a mod that brings realistic, world-based science and technology into Minecraft along with some other additions.
https://aurilis.dev/electrodynamics/
Other
72 stars 19 forks source link

Crash when hurting fake player entity #184

Closed twothe closed 2 years ago

twothe commented 2 years ago

When a player on my server hit an Ars Nouveau Decoy with a weapon the server went into a crash loop:

Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
        at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[?:?]
        at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[?:?]
        at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266) ~[?:?]
        at java.util.Objects.checkIndex(Objects.java:359) ~[?:?]
        at java.util.ArrayList.get(ArrayList.java:427) ~[?:?]
        at electrodynamics.common.event.PlayerHandler.compareArmor(PlayerHandler.java:68) ~[Electrodynamics-1.18.2-0.6.3-10.jar%2389!/:1.18.2-0.6.3-10]
        at electrodynamics.common.event.PlayerHandler.takeDamageWithArmor(PlayerHandler.java:55) ~[Electrodynamics-1.18.2-0.6.3-10.jar%2389!/:1.18.2-0.6.3-10]
        at net.minecraftforge.eventbus.ASMEventHandler_524_PlayerHandler_takeDamageWithArmor_LivingHurtEvent.invoke(.dynamic) ~[?:?]
        at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-5.0.3.jar%232!/:?]
        at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-5.0.3.jar%232!/:?]
        at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-5.0.3.jar%232!/:?]
        at net.minecraftforge.common.ForgeHooks.onLivingHurt(ForgeHooks.java:320) ~[forge-1.18.2-40.1.54-universal.jar%23220!/:?]
        at net.minecraft.world.entity.LivingEntity.m_6475_(LivingEntity.java:1545) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.entity.LivingEntity.m_6469_(LivingEntity.java:1049) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.entity.Entity.m_6075_(Entity.java:450) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.entity.LivingEntity.m_6075_(LivingEntity.java:321) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.entity.Mob.m_6075_(Mob.java:241) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.entity.Entity.m_8119_(Entity.java:413) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.entity.LivingEntity.m_8119_(LivingEntity.java:2215) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.entity.Mob.m_8119_(Mob.java:307) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at com.hollingsworth.arsnouveau.common.entity.EntityDummy.m_8119_(EntityDummy.java:80) ~[ars_nouveau-1.18.2-2.6.3.jar%2352!/:2.6.3]
        at net.minecraft.server.level.ServerLevel.m_8647_(ServerLevel.java:652) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.level.Level.m_46653_(Level.java:486) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.server.level.ServerLevel.m_184063_(ServerLevel.java:319) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.world.level.entity.EntityTickList.m_156910_(EntityTickList.java:54) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.server.level.ServerLevel.m_8793_(ServerLevel.java:299) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        at net.minecraft.server.MinecraftServer.m_5703_(MinecraftServer.java:902) ~[server-1.18.2-20220404.173914-srg.jar%23215!/:?]
        ... 5 more
twothe commented 2 years ago

https://github.com/aurilisdev/Electrodynamics/blob/28a4ac2f901a2bcd584e2fbd77a61406d426c312/src/main/java/electrodynamics/common/event/PlayerHandler.java#L68

The issues seems to be that the size of the given array is not checked.

aurilisdev commented 2 years ago

Fixed it now :)