Hey guys, the problem is, I am making my custom sword and I would like to add an enchanting to it in it's class, like in 1.7.10 I could use: addEnchanting(Enchantment.ENCHANTMENT, TIER); - and it worked, but now in 1.12.2 I don't have idea of what to use instead of "addEnchanting"; but I know that instead of "Enchantment.ENCHANTMENT" - I need to use "Enchantments.ENCHANTMENT". BTW, I'm using eclipse.
There should be a method in ItemStack for adding the enchantment. Probably called addEnchantment() but just look at the Type Hierarchy for ItemStack and it will list all the methods and it should be obvious what to use.
I had this problem too when creative a Blaze Sword for 1.11.2.
I sort of have a solution.
I wasn't able to figure out how to add an enchantment that showed up in the Creative Tab, but I was able to have an enchantment added when the item was crafted.
I did that by first creating an ItemStack that contained my item. Then I modified the stack with ".addEnchantment(enchantment here)". Then I gave that modified stack as an output in a crafting recipe. I'll post the code below.
// Here we create an ItemStack that contains the Blaze Sword.
ItemStack stackBlazeSword = new ItemStack(this);
// Here I modify that ItemStack object by adding an enchantment to it.
stackBlazeSword.addEnchantment(Enchantment.fireAspect, 2);
// And here I add a recipe that gives the enchanted stack to the player. This doens't make it enchanted in the Creative tab though, so they only can get the enchantment when they craft this recipe, unfortunately.
GameRegistry.addShapedRecipe(stackBlazeSword, "r","r","b",'r', Items.blaze_rod,'b',Items.stick);
-------------------
Important! Overlooked! [Edited] this code is for 1.7.10. I backported my mod to 1.7.10, so don't try to add this code to 1.12 because some of the names are different and it will error.
-------------------
Crap. I hope that code formatting worked. I'm pretty new to forums and used the code formatter but it looks odd. Maybe I'll try the Preview button.
Anyway, I wanted to point out that it only says "new ItemStack(this);" on line 1 because all of this code is inside of my BlazeSword class inside of the Constructor. Otherwise "this" would have to be replaced with a reference to the item that can navigate to it. Like yourmod.items.blazeSwordVariableForRegistering or whatnot.
Post Script / Apology:
I'm pretty new to modding (just started last week), so forgive me if I have bad Java or Java practices. I've been programming for 17 years, but in C++, C#, Python, and Lua. Java is an absolute nightmare so far. It's needlessly abstract. I'm what they'd call a "functional programmer". Less heavy on the OO stuff, less classes, and more just point A to B functions and logic.
Hey guys, the problem is, I am making my custom sword and I would like to add an enchanting to it in it's class, like in 1.7.10 I could use: addEnchanting(Enchantment.ENCHANTMENT, TIER); - and it worked, but now in 1.12.2 I don't have idea of what to use instead of "addEnchanting"; but I know that instead of "Enchantment.ENCHANTMENT" - I need to use "Enchantments.ENCHANTMENT". BTW, I'm using eclipse.
Could someone help me, please?
There should be a method in ItemStack for adding the enchantment. Probably called addEnchantment() but just look at the Type Hierarchy for ItemStack and it will list all the methods and it should be obvious what to use.
I had this problem too when creative a Blaze Sword for 1.11.2.
I sort of have a solution.
I wasn't able to figure out how to add an enchantment that showed up in the Creative Tab, but I was able to have an enchantment added when the item was crafted.
I did that by first creating an ItemStack that contained my item. Then I modified the stack with ".addEnchantment(enchantment here)". Then I gave that modified stack as an output in a crafting recipe. I'll post the code below.
-------------------
Important! Overlooked! [Edited] this code is for 1.7.10. I backported my mod to 1.7.10, so don't try to add this code to 1.12 because some of the names are different and it will error.
-------------------
Crap. I hope that code formatting worked. I'm pretty new to forums and used the code formatter but it looks odd. Maybe I'll try the Preview button.
Anyway, I wanted to point out that it only says "new ItemStack(this);" on line 1 because all of this code is inside of my BlazeSword class inside of the Constructor. Otherwise "this" would have to be replaced with a reference to the item that can navigate to it. Like yourmod.items.blazeSwordVariableForRegistering or whatnot.
Post Script / Apology:
I'm pretty new to modding (just started last week), so forgive me if I have bad Java or Java practices. I've been programming for 17 years, but in C++, C#, Python, and Lua. Java is an absolute nightmare so far. It's needlessly abstract. I'm what they'd call a "functional programmer". Less heavy on the OO stuff, less classes, and more just point A to B functions and logic.
[Edit]: Spelling