0
0
mirror of https://github.com/Wurst-Imperium/Wurst7.git synced 2024-09-20 09:16:20 +02:00

Fix crash when a villager sells a corrupted book

This commit is contained in:
Alexander01998 2023-03-08 00:34:52 +01:00
parent ec22d9827c
commit f679c689e6

View File

@ -427,12 +427,20 @@ public final class AutoLibrarianHack extends Hack
if(enchantmentNbt.isEmpty())
continue;
NbtList bookNbt =
EnchantedBookItem.getEnchantmentNbt(tradeOffer.getSellItem());
NbtList bookNbt = EnchantedBookItem.getEnchantmentNbt(stack);
String enchantment = bookNbt.getCompound(0).getString("id");
int level = bookNbt.getCompound(0).getInt("lvl");
int price = tradeOffer.getAdjustedFirstBuyItem().getCount();
return new BookOffer(enchantment, level, price);
BookOffer bookOffer = new BookOffer(enchantment, level, price);
if(!bookOffer.isValid())
{
System.out.println("Found invalid enchanted book offer.\n"
+ "NBT data: " + stack.getNbt());
continue;
}
return bookOffer;
}
return null;