AzizD 0 Posted January 25 Share Posted January 25 I created a custom item that extends TieredItem. I want it to be enchantable through the enchantment table with Sharpnes, Looting etc. I can enchant but only the unbreaking enchantment shows up. Quote Link to post Share on other sites
Draco18s 2426 Posted January 25 Share Posted January 25 There are functions that define this. The default checks what kind of item things are and allows or denies various enchantments. TieredItem only allows Unbreaking (because that's the default). Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given. Link to post Share on other sites
AzizD 0 Posted January 25 Author Share Posted January 25 @Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { enchantment = Enchantments.SHARPNESS; return enchantment.canApply(stack.getItem().getDefaultInstance()); } I tried to override this method. Whenever i put the item in the enchantment table game crashes with java.lang.StackOverflowError. Quote Link to post Share on other sites
AzizD 0 Posted January 25 Author Share Posted January 25 @Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { if(enchantment == Enchantments.SHARPNESS) { enchantment.canApply(stack); } return true; } I changed with this but same error. Quote Link to post Share on other sites
kiou.23 26 Posted January 26 Share Posted January 26 55 minutes ago, AzizD said: @Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { if(enchantment == Enchantments.SHARPNESS) { enchantment.canApply(stack); } return true; } I changed with this but same error. well obviously, Enchantment#canApply(), calls ItemStack#CanApplyAtEnchantingTable(), which calls Item#canApplyAtEnchantingTable. Therefore, you got yourself an infinite loop... Quote Link to post Share on other sites
AzizD 0 Posted January 26 Author Share Posted January 26 @Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { Enchantment[] enchantments = { Enchantments.SHARPNESS, Enchantments.LOOTING, Enchantments.FIRE_ASPECT, Enchantments.UNBREAKING, Enchantments.KNOCKBACK, Enchantments.MENDING, }; for(int i=0;i<enchantments.length;i++){ if(enchantments[i] == enchantment){ return true; } } return false; } I wrote this and it worked. Thx. Quote Link to post Share on other sites
diesieben07 7797 Posted January 26 Share Posted January 26 A better way would be to use a Set (probably ImmutableSet in this case). Quote Link to post Share on other sites
AzizD 0 Posted January 26 Author Share Posted January 26 23 minutes ago, diesieben07 said: A better way would be to use a Set (probably ImmutableSet in this case). It looks way better. Thanks for the advice. @Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { Set e = ImmutableSet.of( Enchantments.SHARPNESS, Enchantments.LOOTING, Enchantments.FIRE_ASPECT, Enchantments.UNBREAKING, Enchantments.KNOCKBACK ); return e.contains(enchantment); } Quote Link to post Share on other sites
diesieben07 7797 Posted January 26 Share Posted January 26 Please don't use raw types. Store the Set in a field, don't create it every time. Quote Link to post Share on other sites
AzizD 0 Posted January 26 Author Share Posted January 26 5 minutes ago, diesieben07 said: Please don't use raw types. Store the Set in a field, don't create it every time. I got it. Quote Link to post Share on other sites
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.