1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #3864 from justtos/master

This commit is contained in:
Sfiguz7 2023-07-11 18:29:53 +02:00 committed by GitHub
commit 2ef2e503f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machine
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
@ -20,6 +21,8 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
@ -128,16 +131,25 @@ public class AutoDisenchanter extends AbstractEnchantmentMachine {
ItemMeta bookMeta = book.getItemMeta();
((Repairable) bookMeta).setRepairCost(((Repairable) itemMeta).getRepairCost());
((Repairable) itemMeta).setRepairCost(0);
item.setItemMeta(itemMeta);
book.setItemMeta(bookMeta);
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta();
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
item.removeEnchantment(entry.getKey());
meta.addStoredEnchant(entry.getKey(), entry.getValue(), true);
Enchantment enchantmentToTransfer = entry.getKey();
boolean wasEnchantmentRemoved = itemMeta.removeEnchant(enchantmentToTransfer);
boolean stillHasEnchantment = itemMeta.getEnchants().containsKey(enchantmentToTransfer);
// Prevent future enchantment duplication (#3837)
if (wasEnchantmentRemoved && !stillHasEnchantment) {
meta.addStoredEnchant(enchantmentToTransfer, entry.getValue(), true);
} else {
// Get Enchantment Name
Slimefun.logger().log(Level.SEVERE, "AutoDisenchanter has failed to remove enchantment \"{0}\"", enchantmentToTransfer.getKey().getKey());
}
}
item.setItemMeta(itemMeta);
book.setItemMeta(meta);
}