Ahhh!!! I want custom book for enchantment

Started by dreamingdreamer on

Topic category: Help with Minecraft modding (Java Edition)

Joined Sep 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ahhh!!! I want custom book for enchantment

I tried writing code with ChatGPT.

But it still shows up as a limited enchantment with ...? in the Enchant Table.

How can I put vanilla enchantments on items?

//custom element
@EventBusSubscriber
public class AllowCustomBookEnchant {
@SubscribeEvent
public static void onEnchantabilityCheck(EnchantmentLevelSetEvent event) {
ItemStack stack = event.getItem();

if (stack.getItem() instanceof BlessedBookItem || stack.getItem() instanceof AdvancedBlessedBookItem) {
event.setEnchantLevel(event.getEnchantLevel());
ItemEnchantments enchantments = stack.getEnchantments();
stack.set(DataComponents.ENCHANTMENTS, enchantments);
}
}
//book.java
public class BlessedBookItem extends Item {
public BlessedBookItem(Item.Properties properties) {
super(properties.stacksTo(1).component(DataComponents.ENCHANTABLE, new Enchantable(7))
.component(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY)
.component(DataComponents.REPAIR_COST, 1));
}
public static void addStoredEnchant(ItemStack stack, ItemEnchantments enchants) {
stack.set(DataComponents.ENCHANTMENTS, enchants);
}
public static boolean hasStoredEnchantments(ItemStack stack) {
return stack.has(DataComponents.ENCHANTMENTS);
}
}