Advertisement
Guest User

ItemArmourMF

a guest
Aug 3rd, 2015
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.58 KB | None | 0 0
  1. package minefantasy.mf2.item.armour;
  2.  
  3. import java.util.List;
  4.  
  5. import minefantasy.mf2.MineFantasyII;
  6. import minefantasy.mf2.api.armour.ArmourDesign;
  7. import minefantasy.mf2.api.armour.IElementalResistance;
  8. import minefantasy.mf2.api.armour.ItemArmourMFBase;
  9. import minefantasy.mf2.item.list.ArmourListMF;
  10. import minefantasy.mf2.item.list.CreativeTabMF;
  11. import minefantasy.mf2.item.list.ToolListMF;
  12. import minefantasy.mf2.material.BaseMaterialMF;
  13. import minefantasy.mf2.mechanics.CombatMechanics;
  14. import net.minecraft.creativetab.CreativeTabs;
  15. import net.minecraft.entity.Entity;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.item.EntityEnderPearl;
  18. import net.minecraft.item.EnumRarity;
  19. import net.minecraft.item.Item;
  20. import net.minecraft.item.ItemStack;
  21. import net.minecraft.nbt.NBTTagCompound;
  22. import net.minecraft.util.DamageSource;
  23. import net.minecraftforge.fml.common.registry.GameRegistry;
  24. import net.minecraftforge.fml.relauncher.Side;
  25. import net.minecraftforge.fml.relauncher.SideOnly;
  26.  
  27. public class ItemArmourMF extends ItemArmourMFBase implements IElementalResistance
  28. {
  29.     private int itemRarity;
  30.     private BaseMaterialMF baseMaterial;
  31.    
  32.     public ItemArmourMF(String name, BaseMaterialMF material, ArmourDesign AD, int slot, String tex, int rarity)
  33.     {
  34.         super(name, material.getArmourConversion(), AD, slot, tex);
  35.         baseMaterial = material;
  36.         setUnlocalizedName("minefantasy2:Apparel/"+AD.getName()+"/"+name);
  37.         GameRegistry.registerItem(this, name, MineFantasyII.MODID);
  38.         setCreativeTab(CreativeTabMF.tabArmour);
  39.        
  40.         itemRarity = rarity;
  41.     }
  42.  
  43.     public ItemArmourMF(String name, BaseMaterialMF material, ArmourDesign AD, int slot, String tex, int rarity, float customBulk)
  44.     {
  45.         this(name, material, AD, slot, tex, rarity);
  46.         this.suitBulk = customBulk;
  47.     }
  48.     @Override
  49.     public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type)
  50.     {
  51.         if(type == null && canColour())//bottom layer
  52.         {
  53.             return "minefantasy2:textures/models/armour/"+design.getName()+"/"+texture+ "_cloth.png";
  54.         }
  55.         return "minefantasy2:textures/models/armour/"+design.getName()+"/"+texture+".png";
  56.     }
  57.    
  58.    
  59.    
  60.     @Override
  61.     public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot)
  62.     {
  63.         if(source.isMagicDamage() && this.getMagicResistance(stack, source) > 0.0F)
  64.         {
  65.             return;
  66.         }
  67.         if(source.isFireDamage() && this.getFireResistance(stack, source) > 0.0F)
  68.         {
  69.             return;
  70.         }
  71.         if(ArmourListMF.isUnbreakable(baseMaterial, entity))
  72.         {
  73.             return;
  74.         }
  75.         super.damageArmor(entity, stack, source, damage, slot);
  76.     }
  77.  
  78.     @Override
  79.     public float getMagicResistance(ItemStack item, DamageSource source)
  80.     {
  81.         return material.magicResistanceModifier;
  82.     }
  83.  
  84.     @Override
  85.     public float getFireResistance(ItemStack item, DamageSource source)
  86.     {
  87.         return material.fireResistanceModifier;
  88.     }
  89.  
  90.     @Override
  91.     public float getArrowDeflection(ItemStack item, DamageSource source)
  92.     {
  93.         return (design == ArmourDesign.MAIL || design == ArmourDesign.PLATE) ? 0.5F : 0.0F;
  94.     }
  95.  
  96.     @Override
  97.     public float getBaseResistance(ItemStack item, DamageSource source)
  98.     {
  99.         if(baseMaterial == BaseMaterialMF.enderforge && source.getSourceOfDamage() != null && source.getSourceOfDamage() instanceof EntityEnderPearl)
  100.         {
  101.             return 100F;
  102.         }
  103.         return 0;
  104.     }
  105.    
  106.    
  107.     @Override
  108.     public EnumRarity getRarity(ItemStack item)
  109.     {
  110.         int lvl = itemRarity + 1;
  111.        
  112.         if(item.isItemEnchanted())
  113.         {
  114.             if(lvl == 0)
  115.             {
  116.                 lvl++;
  117.             }
  118.             lvl ++;
  119.         }
  120.         if(design == ArmourDesign.PLATE)
  121.         {
  122.             lvl ++;
  123.         }
  124.         if(lvl >= ToolListMF.rarity.length)
  125.         {
  126.             lvl = ToolListMF.rarity.length-1;
  127.         }
  128.         return ToolListMF.rarity[lvl];
  129.     }
  130.     @Override
  131.     protected boolean isUnbreakable()
  132.     {
  133.         return baseMaterial == BaseMaterialMF.enderforge;
  134.     }
  135.    
  136.     @Override
  137.     public void getSubItems(Item item, CreativeTabs tab, List list)
  138.     {
  139.         if(this != ArmourListMF.leather[0])
  140.         {
  141.             return;
  142.         }
  143.         addSet(list, ArmourListMF.leather);
  144.        
  145.         addSet(list, ArmourListMF.chainmail);
  146.         addSet(list, ArmourListMF.fieldplate);
  147.     }
  148.  
  149.     private void addSet(List list, Item[] items)
  150.     {
  151.         for(Item item:items)
  152.         {
  153.             list.add(new ItemStack(item));
  154.         }
  155.     }
  156.    
  157.     @Override
  158.     protected float getACModifier(EntityLivingBase player, ItemStack armour, DamageSource source, double damage)
  159.     {
  160.         if(source.getSourceOfDamage() != null && source.getSourceOfDamage() instanceof EntityLivingBase)
  161.         {
  162.             if(isUndedEfficient())
  163.             {
  164.                 if(((EntityLivingBase)source.getSourceOfDamage()).isEntityUndead())
  165.                 {
  166.                     return CombatMechanics.specialUndeadModifier;
  167.                 }
  168.                 if(source.getSourceOfDamage().getClass().getName().contains("Werewolf"))
  169.                 {
  170.                     return CombatMechanics.specialWerewolfModifier;
  171.                 }
  172.             }
  173.         }
  174.         return 1.0F;
  175.     }
  176.  
  177.     private boolean isUndedEfficient()
  178.     {
  179.         return baseMaterial == BaseMaterialMF.silver || baseMaterial == BaseMaterialMF.ornate;
  180.     }
  181.    
  182. //  @Override
  183. //  @SideOnly(Side.CLIENT)
  184. //    public void registerIcons(IIconRegister reg)
  185. //    {
  186. //      if(!canColour())
  187. //      {
  188. //          super.registerIcons(reg);
  189. //      }
  190. //      else
  191. //      {
  192. //          String baseLayer = isMetal() ? "" : "_overlay";
  193. //          this.armourIcon = reg.registerIcon(this.getIconString()+baseLayer);
  194. //          String dyeLayer = isMetal() ? "_cloth" : "";
  195. //          this.clothIcon = reg.registerIcon(this.getIconString()+dyeLayer);
  196. //      }
  197. //    }
  198.  
  199.    
  200.     public boolean canColour()
  201.     {
  202.         if(material.name.equalsIgnoreCase("hide") || material.name.equalsIgnoreCase("rough"))
  203.         {
  204.             return false;
  205.         }
  206.         return design == ArmourDesign.PADDING || design == ArmourDesign.LEATHER || design == ArmourDesign.CLOTH || isMetal();
  207.     }
  208.     public boolean isMetal()
  209.     {
  210.         return design == ArmourDesign.MAIL || design == ArmourDesign.PLATE;
  211.     }
  212.    
  213.     //COLOURING
  214.     public int defaultColour = 10511680;
  215.    
  216.     /**
  217.      * Return whether the specified armor ItemStack has a color.
  218.      */
  219.     @Override
  220.     public boolean hasColor(ItemStack item)
  221.     {
  222.         return !canColour() ? false : (!item.hasTagCompound() ? false : (!item.getTagCompound().hasKey("display", 10) ? false : item.getTagCompound().getCompoundTag("display").hasKey("color", 3)));
  223.     }
  224.  
  225.     /**
  226.      * Return the color for the specified armor ItemStack.
  227.      */
  228.     @Override
  229.     public int getColor(ItemStack item)
  230.     {
  231.         if (!canColour())
  232.         {
  233.             return -1;
  234.         }
  235.         else
  236.         {
  237.             NBTTagCompound nbttagcompound = item.getTagCompound();
  238.  
  239.             if (nbttagcompound == null)
  240.             {
  241.                 return defaultColour;
  242.             }
  243.             else
  244.             {
  245.                 NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
  246.                 return nbttagcompound1 == null ? defaultColour : (nbttagcompound1.hasKey("color", 3) ? nbttagcompound1.getInteger("color") : defaultColour);
  247.             }
  248.         }
  249.     }
  250.    
  251.     /**
  252.      * Remove the color from the specified armor ItemStack.
  253.      */
  254.     @Override
  255.     public void removeColor(ItemStack item)
  256.     {
  257.         if (canColour())
  258.         {
  259.             NBTTagCompound nbttagcompound = item.getTagCompound();
  260.  
  261.             if (nbttagcompound != null)
  262.             {
  263.                 NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
  264.  
  265.                 if (nbttagcompound1.hasKey("color"))
  266.                 {
  267.                     nbttagcompound1.removeTag("color");
  268.                 }
  269.             }
  270.         }
  271.     }
  272.  
  273.     @Override
  274.     public void setColor(ItemStack item, int colour)
  275.     {
  276.         if (!canColour())
  277.         {
  278.             return;
  279.         }
  280.         else
  281.         {
  282.             NBTTagCompound nbttagcompound = item.getTagCompound();
  283.  
  284.             if (nbttagcompound == null)
  285.             {
  286.                 nbttagcompound = new NBTTagCompound();
  287.                 item.setTagCompound(nbttagcompound);
  288.             }
  289.  
  290.             NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
  291.  
  292.             if (!nbttagcompound.hasKey("display", 10))
  293.             {
  294.                 nbttagcompound.setTag("display", nbttagcompound1);
  295.             }
  296.  
  297.             nbttagcompound1.setInteger("color", colour);
  298.         }
  299.     }
  300.     @Override
  301.     public float getMagicAC(float AC, DamageSource source, double damage, EntityLivingBase player)
  302.     {
  303.         if(damage > 1 && material.isMythic)
  304.         {
  305.             return AC;
  306.         }
  307.         return 0F;
  308.     }
  309.  
  310.     @Override
  311.     public String getSuitWeigthType(ItemStack item)
  312.     {
  313.         if(design == ArmourDesign.MAIL)
  314.         {
  315.             return "medium";
  316.         }
  317.         if(design == ArmourDesign.PLATE)
  318.         {
  319.             return "heavy";
  320.         }
  321.         return super.getSuitWeigthType(item);
  322.     }
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement