@@ -612,33 +612,37 @@ private static List<EnchantmentInstance> getEnchantmentList(Registry<Enchantment
612612
613613 // Same as above method, except does not assume the seed has been cracked. If it
614614 // hasn't returns the clue given by the server
615+ @ Nullable
615616 public static List <EnchantmentInstance > getEnchantmentsInTable (int slot ) {
616617 LocalPlayer player = Minecraft .getInstance ().player ;
617618 assert player != null ;
618619 Registry <Enchantment > enchantmentRegistry = player .registryAccess ().lookupOrThrow (Registries .ENCHANTMENT );
619620
620621 CrackState crackState = Configs .enchCrackState ;
621- EnchantmentMenu enchContainer = (EnchantmentMenu ) player .containerMenu ;
622+
623+ if (!(player .containerMenu instanceof EnchantmentMenu enchMenu )) {
624+ return null ;
625+ }
622626
623627 if (crackState != CrackState .CRACKED ) {
624- if (enchContainer .enchantClue [slot ] == -1 ) {
628+ if (enchMenu .enchantClue [slot ] == -1 ) {
625629 // if we haven't cracked it, and there's no clue, then we can't give any
626630 // information about the enchantment
627631 return null ;
628632 } else {
629633 // return a list containing the clue
630- Holder <Enchantment > enchantment = enchantmentRegistry .asHolderIdMap ().byId (enchContainer .enchantClue [slot ]);
634+ Holder <Enchantment > enchantment = enchantmentRegistry .asHolderIdMap ().byId (enchMenu .enchantClue [slot ]);
631635 if (enchantment == null ) {
632636 return null ;
633637 }
634- return new ArrayList <>(Collections .singletonList (new EnchantmentInstance (enchantment , enchContainer .levelClue [slot ])));
638+ return new ArrayList <>(Collections .singletonList (new EnchantmentInstance (enchantment , enchMenu .levelClue [slot ])));
635639 }
636640 } else {
637641 // return the enchantments using our cracked seed
638642 RandomSource rand = RandomSource .create ();
639643 int xpSeed = possibleXPSeeds .iterator ().next ();
640- ItemStack enchantingStack = enchContainer .getSlot (0 ).getItem ();
641- int enchantLevels = enchContainer .costs [slot ];
644+ ItemStack enchantingStack = enchMenu .getSlot (0 ).getItem ();
645+ int enchantLevels = enchMenu .costs [slot ];
642646 return getEnchantmentList (enchantmentRegistry , rand , xpSeed , enchantingStack , slot , enchantLevels , MultiVersionCompat .INSTANCE .getProtocolVersion ());
643647 }
644648 }
0 commit comments