So I was looking through the item class for bows in Minecraft, and I noticed that the enchantments are implemented right there in the item class like this:
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0)
{
entityarrow.setFire(100);
}
Does anybody enchantments are implemented on armor, swords, and tools? Thank you in advance
Yeah, I am looking to just affect my own custom tools and armor at the moment. The coding for enchants on the bow was pretty easy to find, but I can't find the coding for enchants like fortune in any of the tool classes or item classes. Any idea where I should be looking?
thats not at all how you mess with enchantments. You use eventhandlers in the new enchantment class. look at the code for more swords mod if you wanna see how its done
As Lithial mentioned, you are going about this the wrong way. The enchantment class is not used to add a new effect to the game, the enchantment is simply a wrapper for the enchantment data (name, id, level) along with some extra logic which is used by the enchantment table and a few other things. In 1.7.10 and earlier, an enchantment is just an id and a level written to the NBT of an ItemStack's tag compound. This means that you can check for an enchantment on an item from any situation where you have an item (for example, if a player collides with your new block, you can grab the held item of the player and use the same EnchantmentHelper class and methods as vanilla to create an effect. (for example, a block that will explode if a player walks on it with smite on a held item). So, lets say you want to add an enchantment which works similarly to fire aspect but adds the slowness potion instead. From the surface it would seem that you would have to put the code for this effect into the vanilla method (such as the one you were looking at in the main post) however that is the completely wrong way to look at things. Minecraft Forge has several event busses which allow you to have code that gets notified or triggered whenever a certain action happens. These events are extremely easy to use once you understand them, and can be used to do everything from new potion effects, or adding rare drops to existing mobs. I wrote a comprehensive guide to the forge event system which you can find here. Events are a modders best fried. If you have any issues with events, feel free to send me a private message and I will gladly help you with that.
A note about Minecraft 1.8, Enchantments in Minecraft 1.8 have shifted away from the hard coded system mentioned in this thread, there are a wide range of methods which allow you to do almost anything you will ever need. This new system in 1.8 can replace the purpose for events, and it would probably be better if you use that system over events when possible. That being said, if you need to do things that are not supported, like right click effects, events will still be required.
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0)
{
entityarrow.setFire(100);
}
Does anybody enchantments are implemented on armor, swords, and tools? Thank you in advance
A note about Minecraft 1.8, Enchantments in Minecraft 1.8 have shifted away from the hard coded system mentioned in this thread, there are a wide range of methods which allow you to do almost anything you will ever need. This new system in 1.8 can replace the purpose for events, and it would probably be better if you use that system over events when possible. That being said, if you need to do things that are not supported, like right click effects, events will still be required.
Farewell everyone o/