I'm using onUpdate to try and give an item two enchantments. The Item is uncraftable, found only in random Stasis Boxes that generate buried under the ground. However, once I get one from the box, it never enchants, should I only be giving it on enchant or can I do multiple enchants?
package projectmayhem1983.wheeloftime.item;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.world.World;
public class ItemHeronSword extends ItemSword {
public ItemHeronSword(ToolMaterial material) {
super(material);
this.setFull3D();
}
public void onUpdate(ItemStack stack, World world, EntityPlayer player) {
if (!stack.isItemEnchanted()) {
stack.addEnchantment(Enchantment.sharpness, 3);
stack.addEnchantment(Enchantment.unbreaking, 3);
}
}
}
I do not know if you need to know how the sword is generating , but here is the code from my stasis box that generates a random item. From what I've been reading on the forums and seen from watching tutorials, this should work. Unless I should be using just one enchantment, right?
Your onUpdate method doesn't override Item#onUpdate because it has the wrong signature (name, number of arguments and argument types). The signature of Item#onUpdate is onUpdate(ItemStack,World,Entity,int,boolean).
I suggest adding the @Override annotation to any override method so you get a compiler error if it doesn't actually override a method of the superclass. This tutorial explains method overriding in more detail.
Your IDE should also be able to auto-generate override methods for you.
I wouldn't really recommend applying the enchantments from Item#onUpdate, you should just add the enchantments to the ItemStack before you add it to your ChestGenHooks. You could also override Item#getChestGenBase to apply the enchantments, this is called whenever a ChestGenHooks generates your item.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I'm using onUpdate to try and give an item two enchantments. The Item is uncraftable, found only in random Stasis Boxes that generate buried under the ground. However, once I get one from the box, it never enchants, should I only be giving it on enchant or can I do multiple enchants?
I do not know if you need to know how the sword is generating , but here is the code from my stasis box that generates a random item. From what I've been reading on the forums and seen from watching tutorials, this should work. Unless I should be using just one enchantment, right?
Your onUpdate method doesn't override Item#onUpdate because it has the wrong signature (name, number of arguments and argument types). The signature of Item#onUpdate is onUpdate(ItemStack,World,Entity,int,boolean).
I suggest adding the @Override annotation to any override method so you get a compiler error if it doesn't actually override a method of the superclass. This tutorial explains method overriding in more detail.
Your IDE should also be able to auto-generate override methods for you.
I wouldn't really recommend applying the enchantments from Item#onUpdate, you should just add the enchantments to the ItemStack before you add it to your ChestGenHooks. You could also override Item#getChestGenBase to apply the enchantments, this is called whenever a ChestGenHooks generates your item.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.