Started by
dreamingdreamer
on
Topic category: Help with Minecraft modding (Java Edition)
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);
}
}
Edited by dreamingdreamer on Fri, 10/17/2025 - 12:56
do you change the ItemEnchantments.EMPTY part for the item? also, for the question in your text, custom tools already allow enchants provided they are in the correct enchantable tag (can be seen through the element tags tab on the left (should already default to the enchantable tag of the set item tool type))
hmm...But it doesn't work... I want to know why it doesn't work.
I've tried many things, but most of them don't work.
Is there any checklist for when an enchantment is marked as "Limited Enchantment"?
ah, I use Mcreator newest version, neoforge 21.8.31
... wait, I'll try somethings
... wow... ChatGPT didn't tell me that.(that is element tags)
thank you for your help
Knowledge++