diff options
author | feildmaster <admin@feildmaster.com> | 2012-12-20 20:05:00 -0600 |
---|---|---|
committer | feildmaster <admin@feildmaster.com> | 2012-12-20 20:51:51 -0600 |
commit | f4836fb42813cbd7bfaf2cca35ac50cc07fbdc98 (patch) | |
tree | 65862b5b38ed2ef5f138cf4073f24c826564308b /src/main/java/net/minecraft/server/ContainerEnchantTable.java | |
parent | bd0daa6d54d00845f33af75bed2bffa3a8fae85f (diff) | |
download | craftbukkit-f4836fb42813cbd7bfaf2cca35ac50cc07fbdc98.tar craftbukkit-f4836fb42813cbd7bfaf2cca35ac50cc07fbdc98.tar.gz craftbukkit-f4836fb42813cbd7bfaf2cca35ac50cc07fbdc98.tar.lz craftbukkit-f4836fb42813cbd7bfaf2cca35ac50cc07fbdc98.tar.xz craftbukkit-f4836fb42813cbd7bfaf2cca35ac50cc07fbdc98.zip |
Add the ability to make Enchanted Books. Fixes BUKKIT-3220
Diffstat (limited to 'src/main/java/net/minecraft/server/ContainerEnchantTable.java')
-rw-r--r-- | src/main/java/net/minecraft/server/ContainerEnchantTable.java | 25 |
1 files 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 c0d99318..6819a606 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<org.bukkit.enchantments.Enchantment, Integer> 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); } } |