Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-19 13:00:06 +01:00
[Bleeding] Correctly enchant books. Fixes BUKKIT-5302
Books can now recieve more than one enchantment. As such, breaking out of the loop after only 1 enchantment is applied is not the correct behavior. This commit also reworks some of the logic surrounding the application of enchantments to the item. By checking if the event doesn't add any enchantments rather than if the original enchantments list is empty, the application code is only reached if enchantments are applied, rendering the "applied" boolean no longer necessary. The ItemStack's Item should only be set once, so it is now set outside of the loop based upon whether or not "flag" is true (with "flag" being whether or not the ItemStack's Item is a book).
Dieser Commit ist enthalten in:
Ursprung
068d8a807b
Commit
66471a5326
@ -167,11 +167,14 @@ public class ContainerEnchantTable extends Container {
|
|||||||
this.world.getServer().getPluginManager().callEvent(event);
|
this.world.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
int level = event.getExpLevelCost();
|
int level = event.getExpLevelCost();
|
||||||
if (event.isCancelled() || (level > entityhuman.expLevel && !entityhuman.abilities.canInstantlyBuild) || enchants.isEmpty()) {
|
if (event.isCancelled() || (level > entityhuman.expLevel && !entityhuman.abilities.canInstantlyBuild) || event.getEnchantsToAdd().isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean applied = !flag;
|
if (flag) {
|
||||||
|
itemstack.setItem(Items.ENCHANTED_BOOK);
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
if (flag) {
|
||||||
@ -182,9 +185,6 @@ public class ContainerEnchantTable extends Container {
|
|||||||
|
|
||||||
EnchantmentInstance enchantment = new EnchantmentInstance(enchantId, entry.getValue());
|
EnchantmentInstance enchantment = new EnchantmentInstance(enchantId, entry.getValue());
|
||||||
Items.ENCHANTED_BOOK.a(itemstack, enchantment);
|
Items.ENCHANTED_BOOK.a(itemstack, enchantment);
|
||||||
applied = true;
|
|
||||||
itemstack.setItem((Item) Items.ENCHANTED_BOOK);
|
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
item.addEnchantment(entry.getKey(), entry.getValue());
|
item.addEnchantment(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
@ -193,10 +193,7 @@ public class ContainerEnchantTable extends Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only down level if we've applied the enchantments
|
|
||||||
if (applied) {
|
|
||||||
entityhuman.levelDown(-level);
|
entityhuman.levelDown(-level);
|
||||||
}
|
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
this.a(this.enchantSlots);
|
this.a(this.enchantSlots);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren