From f4836fb42813cbd7bfaf2cca35ac50cc07fbdc98 Mon Sep 17 00:00:00 2001 From: feildmaster Date: Thu, 20 Dec 2012 20:05:00 -0600 Subject: [PATCH] Add the ability to make Enchanted Books. Fixes BUKKIT-3220 --- .../server/ContainerEnchantTable.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTable.java b/src/main/java/net/minecraft/server/ContainerEnchantTable.java index c0d99318d7..6819a60643 100644 --- a/src/main/java/net/minecraft/server/ContainerEnchantTable.java +++ b/src/main/java/net/minecraft/server/ContainerEnchantTable.java @@ -170,17 +170,34 @@ public class ContainerEnchantTable extends Container { return false; } - // TODO: Apply Diffs - entityhuman.levelDown(-level); + boolean applied = !flag; for (Map.Entry entry : event.getEnchantsToAdd().entrySet()) { try { - item.addEnchantment(entry.getKey(), entry.getValue()); + if (flag) { + int enchantId = entry.getKey().getId(); + if (Enchantment.byId[enchantId] == null) { + continue; + } + + EnchantmentInstance enchantment = new EnchantmentInstance(enchantId, entry.getValue()); + Item.ENCHANTED_BOOK.a(itemstack, enchantment); + applied = true; + itemstack.id = Item.ENCHANTED_BOOK.id; + break; + } else { + item.addEnchantment(entry.getKey(), entry.getValue()); + } } catch (IllegalArgumentException e) { /* Just swallow invalid enchantments */ } - // CraftBukkit end } + // Only down level if we've applied the enchantments + if (applied) { + entityhuman.levelDown(-level); + } + // CraftBukkit end + this.a(this.enchantSlots); } }