GVmG Posted December 26, 2022 Posted December 26, 2022 (edited) I have made a custom enchantment (of which all behavior is handled separately). I want this item to only apply to my own custom item. I have tried to use different methods, including overriding the "canEnchant" and "canApplyAtEnchantingTable" methods and such, but somehow that ends up not letting me enchant anything When I fall back to trying to use the custom EnchantmentCategory, that's when it lets me enchant the custom item... and everything else in the game. My enchantment code: public class SpaciousEnchantment extends Enchantment { public static final EnchantmentCategory ENCH_BACKPACK=EnchantmentCategory.create("backpack_enchants", (i) -> i==BackpackMod.ITEM_BACKPACK.get()); public SpaciousEnchantment() { super(Rarity.VERY_RARE, ENCH_BACKPACK, new EquipmentSlot[]{}); } public static int rowsPerLevel(int level) { if (level==1) return 2; if (level==2) return 4; if (level==3) return 6; return 1; } //we override isCurse and the getFullName methods so we can make this un-removable but have a custom color. @Override public boolean isCurse() {return true;} @Override public Component getFullname(int pLevel) { MutableComponent mutablecomponent = Component.translatable(this.getDescriptionId()); mutablecomponent.withStyle(ChatFormatting.GREEN); //mutablecomponent.withStyle(ChatFormatting.GRAY); if (pLevel != 1 || this.getMaxLevel() != 1) { mutablecomponent.append(" ").append(Component.translatable("enchantment.level." + pLevel)); } return mutablecomponent; } @Override public boolean isTreasureOnly() {return true;} @Override public boolean isTradeable() {return false;} @Override public boolean isDiscoverable() {return false;} @Override public int getMaxLevel() {return 3;} } I suspected the issue was the EquipmentSlot stuff, but I tried making it {EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND} and that changed absolutely nothing either, allowing every item in the game to be enchanted. EDIT: I even tried the "canApplyAtEnchantingTable" method in the item class itself and again, nothing changed (since that only affects the item itself, not every other item). i have no idea why it wont work. Edited December 26, 2022 by GVmG solved Quote
ChampionAsh5357 Posted December 26, 2022 Posted December 26, 2022 You need to make a new EnchantmentCategory through the #create method and make it such that the enchantment can only be applied to your item. Quote
GVmG Posted December 26, 2022 Author Posted December 26, 2022 (edited) I did though, and it doesn't seem to be working. It's right at the top of my code. EDIT: cleaned up my IDE's cache, that fixed it. guess it was something behind the scenes with compilation. Edited December 26, 2022 by GVmG solved Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.