Advertisement
Guest User

WastelandEnchantments

a guest
Apr 14th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. package we;
  2. import static net.minecraft.enchantment.EnumEnchantmentType.*;
  3. import net.minecraft.enchantment.Enchantment;
  4. import net.minecraft.enchantment.EnchantmentHelper;
  5. import net.minecraft.enchantment.EnumEnchantmentType;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.potion.Potion;
  8. import net.minecraft.potion.PotionEffect;
  9. import cpw.mods.fml.common.FMLCommonHandler;
  10. import cpw.mods.fml.common.Mod;
  11. import cpw.mods.fml.common.event.FMLPreInitializationEvent;
  12. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  13. import cpw.mods.fml.common.gameevent.TickEvent;
  14. public @Mod(modid = "wastelandenchantments", version = "1.0.1710.b1", name = "WastelandEnchantments") class WastelandEnchantments {
  15.     @Mod.Instance public static WastelandEnchantments instance;
  16.     public static Enchantment   movespeed = new EnchantmentMod(100, 5, armor_feet, "Speed", 4),
  17.                                 digspeed = new EnchantmentMod(101, 6, armor_torso, "Haste", 2),
  18.                                 damage = new EnchantmentMod(102, 7, armor_torso, "Strength",2),
  19.                                 jumpboost = new EnchantmentMod(103, 5, armor_legs, "Jump Boost", 3),
  20.                                 regen = new EnchantmentMod(104, 7, armor_torso, "Regeneration", 2),
  21.                                 resistane = new EnchantmentMod(105, 5, armor_torso, "Resistance", 3),
  22.                                 fireResistance = new EnchantmentMod(106, 6, armor_legs, "Fire Resistance", 1),
  23.                                 breathe = new EnchantmentMod(107, 5, armor_head, "Underwater breathe", 3),
  24.                                 invisibility = new EnchantmentMod(108, 7, armor_head, "Invisibility", 1),
  25.                                 nightvision = new EnchantmentMod(109, 7, armor_head, "Night vision", 1),
  26.                                 absorption = new EnchantmentMod(110, 7, armor_torso, "Absorption", 1),
  27.                                 saturation = new EnchantmentMod(111, 8, armor_head, "Saturation", 1);
  28.     public @Mod.EventHandler void preinit(FMLPreInitializationEvent e){
  29.         FMLCommonHandler.instance().bus().register(this);
  30.     }
  31.     public @SubscribeEvent void playerTick(TickEvent.PlayerTickEvent event){
  32.         if(event.player.worldObj.getTotalWorldTime() % 50 == 0){
  33.             handleEnchantment(Potion.moveSpeed, movespeed, event.player, 0);
  34.             handleEnchantment(Potion.digSpeed, digspeed, event.player, 2);
  35.             handleEnchantment(Potion.damageBoost, damage, event.player, 0);
  36.             handleEnchantment(Potion.jump, jumpboost, event.player, 1);
  37.             handleEnchantment(Potion.regeneration, regen, event.player, 2);
  38.             handleEnchantment(Potion.resistance, resistane, event.player, 2);
  39.             handleEnchantment(Potion.fireResistance, fireResistance, event.player, 1);
  40.             handleEnchantment(Potion.waterBreathing, breathe, event.player, 3);
  41.             handleEnchantment(Potion.invisibility, invisibility, event.player, 3);
  42.             handleEnchantment(Potion.nightVision, nightvision, event.player, 3);
  43.             handleEnchantment(Potion.field_76443_y, saturation, event.player, 3);
  44.            
  45.         }
  46.         if(event.player.worldObj.getTotalWorldTime() % 100 == 0) handleEnchantment(Potion.field_76444_x, absorption, event.player, 2);
  47.     }
  48.     public void handleEnchantment(Potion p, Enchantment e, EntityPlayer plr, int aromorpiece){
  49.         int lvl = EnchantmentHelper.getEnchantmentLevel(e.effectId, plr.getCurrentArmor(aromorpiece));
  50.         if(lvl != 0)plr.addPotionEffect(new PotionEffect(p.id, 100, lvl-1, false));
  51.     }
  52.     public static class EnchantmentMod extends Enchantment{
  53.         private int mxlvl; 
  54.         public EnchantmentMod(int id, int rarity, EnumEnchantmentType eet, String name, int maxlevel) {
  55.             super(id, rarity, eet);
  56.             setName(name);
  57.             mxlvl = maxlevel;
  58.         }
  59.         public @Override  int getMinEnchantability(int l){
  60.             return 5 + (l-1) * 10;
  61.         }
  62.         public @Override  int getMaxEnchantability(int l){
  63.             return getMinEnchantability(l) + 20;
  64.         }
  65.         public @Override int getMaxLevel(){
  66.             return mxlvl;
  67.         }
  68.         public @Override String getName(){
  69.             return name;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement