From 768a75672374114062616ed3c908057aba5589fd Mon Sep 17 00:00:00 2001 From: Xvareon <91329439+Xvareon@users.noreply.github.com> Date: Tue, 2 Jun 2026 01:08:19 +0800 Subject: [PATCH] Fixed a ClassCastError crash in bookshelf loot tables; fixes #899 (#909) --- src/main/java/electroblob/wizardry/loot/RandomSpell.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/electroblob/wizardry/loot/RandomSpell.java b/src/main/java/electroblob/wizardry/loot/RandomSpell.java index f2912c32..0ceb020c 100644 --- a/src/main/java/electroblob/wizardry/loot/RandomSpell.java +++ b/src/main/java/electroblob/wizardry/loot/RandomSpell.java @@ -86,7 +86,13 @@ public class RandomSpell extends LootFunction { // (And WHY does it only return an entity?! The underlying field is always a player so I'm casting it anyway) EntityPlayer player = (EntityPlayer)context.getKillerPlayer(); - Spell spell = pickRandomSpell(stack, random, spellContext, player); + Spell spell; + try { + spell = pickRandomSpell(stack, random, spellContext, player); + } catch (ClassCastException e) { + Wizardry.logger.warn("Failed to apply random_spell function! An item ({}) was passed to a spell's compatibility check that it couldn't handle.", stack.getItem().getRegistryName(), e); + return stack; // Safely bypass processing and return the raw item intact + } if(spell == Spells.none) Wizardry.logger.warn("Tried to apply the random_spell loot function to an item, but no" + " enabled spells matched the criteria specified. Substituting placeholder (metadata 0) item.");