Mod Incompatibility due to Loot Mixin
AnonymousHacker1279 opened this issue ยท 0 comments
The LootItemRandomChanceWithEnchantedBonusCondition mixin seems to cause issues with the GLMs of some mods due to the context.getParam(LootContextParams.DAMAGE_SOURCE) call not doing null checking.
For example, this issue has been mentioned by a user of one of my mods, Immersive Weapons. For them, it seems to occur when using a fishing rod and attempting to reel in a fish. The relevant log section for this issue is below:
[03Feb2025 11:30:16.047] [Server thread/ERROR] [net.minecraft.network.protocol.game.ServerPacketListener/]: Failed to handle packet net.minecraft.network.protocol.game.ServerboundUseItemPacket@5ee67a0f, suppressing error
java.util.NoSuchElementException: minecraft:damage_source
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.LootParams.getParameter(LootParams.java:42) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.LootContext.getParam(LootContext.java:38) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceWithEnchantedBonusCondition.wrapOperation$cij001$ars_nouveau$adjustLooting(LootItemRandomChanceWithEnchantedBonusCondition.java:1532) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceWithEnchantedBonusCondition.wrapOperation$cij001$ars_nouveau$adjustLooting$mixinextras$bridge$19(LootItemRandomChanceWithEnchantedBonusCondition.java) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceWithEnchantedBonusCondition.test(LootItemRandomChanceWithEnchantedBonusCondition.java:47) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceWithEnchantedBonusCondition.test(LootItemRandomChanceWithEnchantedBonusCondition.java:22) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at java.base/java.util.function.Predicate.lambda$and$0(Unknown Source) ~[?:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.predicates.CompositeLootItemCondition.test(CompositeLootItemCondition.java:36) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.predicates.CompositeLootItemCondition.test(CompositeLootItemCondition.java:14) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.predicates.CompositeLootItemCondition.test(CompositeLootItemCondition.java:36) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.predicates.CompositeLootItemCondition.test(CompositeLootItemCondition.java:14) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.neoforged.neoforge.common.loot.LootModifier.apply(LootModifier.java:53) ~[neoforge-21.1.115-universal.jar%23451!/:?]
at TRANSFORMER/[email protected]/net.neoforged.neoforge.common.CommonHooks.modifyLoot(CommonHooks.java:1070) ~[neoforge-21.1.115-universal.jar%23451!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.LootTable.getRandomItems(LootTable.java:127) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.level.storage.loot.LootTable.getRandomItems(LootTable.java:121) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.entity.projectile.FishingHook.retrieve(FishingHook.java:459) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.item.FishingRodItem.use(FishingRodItem.java:26) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.world.item.ItemStack.use(ItemStack.java:391) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.level.ServerPlayerGameMode.useItem(ServerPlayerGameMode.java:313) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.network.ServerGamePacketListenerImpl.handleUseItem(ServerGamePacketListenerImpl.java:1172) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.network.protocol.game.ServerboundUseItemPacket.handle(ServerboundUseItemPacket.java:45) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.network.protocol.game.ServerboundUseItemPacket.handle(ServerboundUseItemPacket.java:9) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:27) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.TickTask.run(TickTask.java:18) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:148) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:23) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:872) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:170) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:122) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:855) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:849) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:132) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.managedBlock(MinecraftServer.java:821) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:826) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:712) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:267) ~[client-1.21.1-20240808.144430-srg.jar%23450!/:?]
at java.base/java.lang.Thread.run(Unknown Source) [?:?]
Theoretically, this can happen with any mod's GLMs if there is no damage source attached. It would be wise to add a null check on line 32 of the relevant mixin:
int spellLuck = context.getParam(LootContextParams.DAMAGE_SOURCE) instanceof DamageUtil.SpellDamageSource spellDamageSource ? spellDamageSource.getLuckLevel() : 0;