mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-03 13:36:44 +01:00
Add the ability to make Enchanted Books. Fixes BUKKIT-3220
This commit is contained in:
parent
bd0daa6d54
commit
f4836fb428
1 changed files with 21 additions and 4 deletions
|
@ -170,17 +170,34 @@ public class ContainerEnchantTable extends Container {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Apply Diffs
|
boolean applied = !flag;
|
||||||
entityhuman.levelDown(-level);
|
|
||||||
for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
|
for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
|
||||||
try {
|
try {
|
||||||
|
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());
|
item.addEnchantment(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
/* Just swallow invalid enchantments */
|
/* 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);
|
this.a(this.enchantSlots);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue