Skip to content

Commit

Permalink
fix enchant command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunekaer committed Jan 15, 2024
1 parent 0d8404e commit c6f6941
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ private static int enchant(CommandContext<CommandSourceStack> context, Holder.Re
CommandSourceStack source = context.getSource();
Enchantment enchantment = (Enchantment)arg2.value();

var enchant = enchantment.value();
var player = source.getPlayer();
var mainHandItem = getItemInHand(player);
if (mainHandItem == null) {
throw ERROR_MISSING_PLAYER.create();
}

if (!enchant.canEnchant(mainHandItem) || !EnchantmentHelper.isEnchantmentCompatible(EnchantmentHelper.getEnchantments(mainHandItem).keySet(), enchant)) {
if (!enchantment.canEnchant(mainHandItem) || !EnchantmentHelper.isEnchantmentCompatible(EnchantmentHelper.getEnchantments(mainHandItem).keySet(), enchantment)) {
throw ERROR_INCOMPATIBLE.create(mainHandItem.getItem().getName(mainHandItem).getString());
}

Expand All @@ -78,11 +77,11 @@ private static int removeEnchantment(CommandContext<CommandSourceStack> context,
throw ERROR_MISSING_ENCHANTMENT.create(mainHandItem.getItem().getName(mainHandItem).getString(), enchantment.getFullname(1));
}

boolean success = EnchantmentHacks.removeEnchantment(mainHandItem, enchant);
boolean success = EnchantmentHacks.removeEnchantment(mainHandItem, enchantment);
if (success) {
source.sendSuccess(() -> Component.translatable("commands.toolkit.remove_enchant.success", mainHandItem.getItem().getName(mainHandItem).getString(), enchantment.getFullname(1).getString()), false);
} else {
source.sendFailure(Component.translatable("commands.toolkit.remove_enchant.failed", mainHandItem.getItem().getName(mainHandItem).getString(), enchant.getFullname(1).getString()));
source.sendFailure(Component.translatable("commands.toolkit.remove_enchant.failed", mainHandItem.getItem().getName(mainHandItem).getString(), enchantment.getFullname(1).getString()));
}
return success ? 1 : 0;
}
Expand Down

0 comments on commit c6f6941

Please sign in to comment.