Posted April 5, 201510 yr I added a method .smiteaspect onUpdate enchantment to my custom sword. Oddly the text "Smiteaspect 22 " repeats and shows itself over and over and over when hovering over the hotbar Any ideas? @Override /** Makes your Item Enchanted on startup */ public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { stack.addEnchantment(Enchantment.smite, 22); super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); } // Replace the "." after "Enchantment" to see options // The number is the Enchantment Level
April 5, 201510 yr I don't think I understood you in best possible manner. Item#onUpdate(...) is (I think) called EVERY tick when item is inside player's inventory (desn't matter slot) and MAYBE in some other cases (idk, never was a fan of this method, so never checked). Basically what you are doing is adding enchantment over and over again. That isn't your goal, is it? You can check is ench was added and then if not - add it. 1.7.10 is no longer supported by forge, you are on your own.
April 5, 201510 yr Author Thank you ...do you know how I would add this Enchantment "smite" on startup but without adding it over and over and over and over?
April 5, 201510 yr Author just be there as the sword already enchanted in creative ...ie, even if you did not craft it
April 5, 201510 yr To do that you will need to override: @SideOnly(Side.CLIENT) public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) { subItems.add(new ItemStack(itemIn, 1, 0)); } And add any kind of ItemStack with alredy set NBT tag you want. EDIT To give you wider look: onCrafted (or Created, don't remember) is called when you pull item result from crafting grid. There you could add NBT when crafting. Mentioned above getSubItems() allows you to add any number of custom ItemStacks into given tab. If you would like to have custom crafting for this item: e.g: when you put stick + stone you get bolt with NBT "stone" and if stick + iron you get bolt (same item), but with NBT "iron" you will need to make new IRecipy and handle your ItemStack creation. 1.7.10 is no longer supported by forge, you are on your own.
April 6, 201510 yr Author ""To do that you will need to override: Code: [select] @SideOnly(Side.CLIENT) public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) { subItems.add(new ItemStack(itemIn, 1, 0)); } And add any kind of ItemStack with alredy set NBT tag you want."" Sorry I do not really understand ....I am very new at this ..is that code in the Item file and I override it? I can see that the onUpdate keeps updating every so many ticks or something
April 6, 201510 yr Yes, override the method in your custom Item class. And the onUpdate method you used is bad for pre-enchanting purpose. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
April 19, 201510 yr Author I do not really get the NBT stuff but here's what did work for me: @Override public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List list) { //super (par1, par2CreativeTabs, list, EnumEnchantmentType.weapon); // list.add(new ItemStack(par1, 1, 0));} // list.add(new ItemStack(Main.Glistre_Sword, 1, 0)); //Adds string with smite level 22 ItemStack string = new ItemStack(Main.Glistre_Sword); string.addEnchantment(Enchantment.smite, 22); list.add(string); } Didnot need the super constructor even though eclipse says it needs it
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.