This site works best with JavaScript enabled. Please enable JavaScript to get the best experience from this site.
After you have created a package you will then want to create a new class ex. enchWither.
In your newly created class you will want to extend Enchantment and in your constructer you should give it an id and rarity.
Also in the super you will want to put EnumEnchantmentType.TheTypeYouWant
You will then have to set the name in the constructer following the super with this.setName("NameOfEnchantment");
The constructor should look something like this!
public enchWither(int id, int rarity){
super(id, rarity, EnumEnchantmentType.weapon);
this.setName("Wither");
}
After that you will then want to get the min and max enchantibility which can be done using public int ex.
public int getMinEnchantability(int par1){
return 5 + (par1 - 1) * 10;
}
public int getMaxEnchantibility(int par1){
return this.getMinEnchantability(par1) + 20;
}
Now we get the max level of your enchantment using public Int getMaxLevel(){ return (TheMaxLevelYouWant) ex. Sharpness has a max level of V.
Now in your main class you will want to create an @Instance if you don't already have one and here we will register the enchantment with:
public static final Enchantment YourEnchantment = new YourEnchantmentClassName(TheEnchantmentIdYouWantToGiveIt, RarityYouWantToGiveIt);
Rarity is 1/x I'm pretty sure so if you want a rare enchantment type a larger number ex. 100 to get a 1/100 chance of getting it.
You can then add your effects with hooks and you might want to add some stuff to your ClientProxy such as the following:
FMLCommonHandler.instance().bus().register(new ServerTickHandler(Minecraft.getMinecraft()));
Then create a ServerTickHandler class to register the effects for your enchantment.
Here is an example of my Soothing enchantment in the ServerTickHandler.java
package com.Etsy.Main;
import com.Etsy.item.ItemHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraftforge.event.entity.EntityEvent;
public class ServerTickHandler {
private Minecraft mc;
public ServerTickHandler(Minecraft mc){
this.mc = mc;
}
@SubscribeEvent
public void onPlayer(PlayerTickEvent event){
if(event.player.getCurrentArmor(3)!= null){
ItemStack helmets = event.player.getCurrentArmor(3);
if(helmets.getItem() == Items.diamond_helmet || helmets.getItem() == Items.golden_helmet ||helmets.getItem() == Items.iron_helmet ||helmets.getItem() == Items.leather_helmet || helmets.getItem() == Items.chainmail_helmet){
int j = EnchantmentHelper.getEnchantmentLevel(MainRegistry.Soothing.effectId, helmets);
if (j > 0){
event.player.addPotionEffect(new PotionEffect(Potion.regeneration.getId(), 60, j));
}
}
}
}
}
Note j is a variable for the level of the effect!
If you also wanted to do something that adds an effect from a hit with a weapon or bow do something like this:
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase){
int k = EnchantmentHelper.getEnchantmentLevel(MainRegistry.Cursed.effectId, par1ItemStack);
if (k > 0){
par2EntityLivingBase.addPotionEffect(new PotionEffect(Potion.poison.id, 20 * k));
}
Note that the k is a variable for the enchantment level and 20 ticks is 1 second making the enchantment level the amount of seconds the given effect lasts!