Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.88 KB | None | 0 0
  1. package minefantasy.mf2.api.armour;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.List;
  5.  
  6. import minefantasy.mf2.api.helpers.ArmourCalculator;
  7. import minefantasy.mf2.api.helpers.ToolHelper;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.EntityLivingBase;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.ItemArmor;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.util.DamageSource;
  15. import net.minecraft.util.EnumChatFormatting;
  16. import net.minecraft.util.StatCollector;
  17. import net.minecraftforge.common.ISpecialArmor;
  18. import net.minecraftforge.common.util.EnumHelper;
  19. import net.minecraftforge.fml.relauncher.Side;
  20. import net.minecraftforge.fml.relauncher.SideOnly;
  21.  
  22. public class ItemArmourMFBase extends ItemArmor implements ISpecialArmor, IArmourMF, IArmourRating
  23. {
  24.                                                                                 //WHAT SHOULD THIS BE??
  25.    
  26.     private int piece;
  27.     private int baseRating;
  28.     public float baseAR;
  29.     public int enchantment;
  30.     public float armourWeight;
  31.     public ArmourMaterialMF material;
  32.     protected float suitBulk;
  33.    
  34.     public static ArmourDesign design;
  35.     public static String texture;
  36.    
  37.    
  38.     public static ArmorMaterial baseMaterial = EnumHelper.addArmorMaterial("MF Armour Base","minefantasy2:textures/models/armour/"+design.getName()+"/"+texture, 0, new int[]{2, 6, 5, 2}, 0);
  39.    
  40.     public static final DecimalFormat decimal_format = new DecimalFormat("#.#");
  41.    
  42.     public ItemArmourMFBase(String name, ArmourMaterialMF material, ArmourDesign AD, int slot, String tex)
  43.     {
  44.         super(baseMaterial, 0, slot);
  45.         this.material = material;
  46.         baseAR = material.baseAR;
  47.         armourWeight = AD.getWeight() * material.armourWeight;
  48.         enchantment = material.enchantment;
  49.         this.piece = slot;
  50.         design = AD;
  51.         suitBulk = design.getBulk();
  52.         texture = tex;
  53.         float baseDura = material.durability * design.getDurability()/2F;
  54.         float dura = baseDura /2F + (baseDura /2F * ArmourCalculator.sizes[slot] / ArmourCalculator.sizes[1]);
  55.         this.setMaxDamage((int)dura);
  56.         this.setUnlocalizedName(name);
  57.        
  58.         baseRating = ArmourCalculator.translateToVanillaAR(getProtectionRatio()+1F, baseMaterial.getDamageReductionAmount(slot), 15);
  59.     }
  60.     /*  Piece | Slot
  61.      *  0     | 3
  62.      *  1     | 2
  63.      *  2     | 1
  64.      *  3     | 0 */
  65.     @Override
  66.     public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot)
  67.     {
  68.         stack.damageItem((int)(damage/5F)+1, entity);
  69.     }
  70.  
  71.     @Override
  72.     public int getArmorDisplay(EntityPlayer player, ItemStack armour, int slot)
  73.     {
  74.         /*
  75.         float max = (float)armour.getMaxDamage();
  76.         float dam = max - (float)armour.getItemDamage();
  77.        
  78.         return (int)Math.round(5F / max * dam);
  79.         */
  80.         return baseRating;
  81.     }
  82.  
  83.     @Override
  84.     public ArmorProperties getProperties(EntityLivingBase player, ItemStack armour, DamageSource source, double damage, int slot)
  85.     {
  86.         float AC = getProtectionRatio();
  87.        
  88.         if(ArmourCalculator.advancedDamageTypes && !player.worldObj.isRemote)
  89.         {
  90.             AC = ArmourCalculator.modifyACForType(source, AC, design.getProtectiveTraits()[0], design.getProtectiveTraits()[1]);
  91.         }
  92.         AC *= getACModifier(player, armour, source, damage);
  93.        
  94.         if(source == DamageSource.fall && design == ArmourDesign.PLATE)
  95.         {
  96.             AC = 1F/material.armourWeight;
  97.         }
  98.         else if(source.isMagicDamage())
  99.         {
  100.             AC = getMagicAC(AC, source, damage, player);
  101.         }
  102.         else if(source == DamageSource.onFire)
  103.         {
  104.             AC *= getACForBurn();
  105.         }
  106.         else if(source.isUnblockable())
  107.         {
  108.             AC *= getUnblockableResistance(armour, source);
  109.         }
  110.         AC = ToolHelper.modifyArmourRating(armour, AC);
  111.         if(player.getEntityData().hasKey("MF_ZombieArmour"))
  112.         {
  113.             AC -= 1.5F;
  114.             if(AC < 0)AC = 0;
  115.         }
  116.         AC++;//because 1.0AC = no armour so it adds ontop of this
  117.        
  118.         double totalPercent = ArmourCalculator.convertToPercent(AC);
  119.         double maxPercent = 0.99D;//max percentage is 99% damage to avoid immunity
  120.        
  121.         if(totalPercent > maxPercent)
  122.         {
  123.             totalPercent = maxPercent;
  124.         }
  125.        
  126.         double percent = totalPercent*scalePiece();
  127.        
  128.         float max = (float) ((getMaxDamage() + 1 - armour.getItemDamage()) * (percent*25F));//I don't know how this variable works
  129.        
  130.         return new ArmorProperties(0, percent, (int)max);
  131.     }
  132.    
  133.     private float getACForBurn()
  134.     {
  135.         return armourWeight >= ArmourCalculator.ACArray[1] ? 0.1F : armourWeight >= ArmourCalculator.ACArray[0] ? 0.05F : 0F;
  136.     }
  137.     public float getUnblockableResistance(ItemStack item, DamageSource source)
  138.     {
  139.         return 0F;
  140.     }
  141.    
  142.     public float getMagicAC(float AC, DamageSource source, double damage, EntityLivingBase player)
  143.     {
  144.         return 0F;
  145.     }
  146.     protected float getACModifier(EntityLivingBase player, ItemStack armour, DamageSource source, double damage)
  147.     {
  148.         return 1.0F;
  149.     }
  150.     public float scalePiece()
  151.     {
  152.         return ArmourCalculator.sizes[piece];
  153.     }
  154.  
  155.     private float getProtectionRatio()
  156.     {
  157.         return material.baseAR*design.getRating();
  158.     }
  159.  
  160.     @SideOnly(Side.CLIENT)
  161.     @Override
  162.     public void addInformation(ItemStack armour, EntityPlayer user, List list, boolean extra)
  163.     {
  164.         super.addInformation(armour, user, list, extra);
  165.        
  166.         if(ArmourCalculator.advancedDamageTypes)
  167.         {
  168.             list.add("");
  169.            
  170.             float cut = design.getProtectiveTraits()[0]*100F;
  171.             float blunt = design.getProtectiveTraits()[1]*100F;
  172.            
  173.             list.add(StatCollector.translateToLocal("attribute.armour.cuttingresistance") + " = " +(int)cut + "%");
  174.             list.add(StatCollector.translateToLocal("attribute.armour.bluntresistance") + " = " +(int)blunt + "%");
  175.         }
  176.         list.add(StatCollector.translateToLocal("attribute.weight.name") + ": " + Math.round(getPieceWeight(armour, piece)));
  177.         /*
  178.         int rating = ArmourCalculator.getArmourRatingLevel(user, armour, slot);
  179.         int equipped = ArmourCalculator.getArmourRatingLevel(user, user.getCurrentArmor(3-slot), slot);
  180.        
  181.         if(equipped > 0 && rating != equipped)
  182.         {
  183.             int d = rating-equipped;
  184.             if(d > 0)
  185.             {
  186.                 attatch += EnumChatFormatting.DARK_GREEN;
  187.             }
  188.             if(d < 0)
  189.             {
  190.                 attatch += EnumChatFormatting.RED;
  191.             }
  192.             attatch += " (" + (d > 0 ? "+" : "") + d +")";
  193.         }
  194.         if(MineFantasyAPI.isInDebugMode)
  195.         {
  196.             list.add(decimal_format.format(getPieceWeight(armour, slot)) + " Kg" + " (" + getACName() + " Armour" + ")");
  197.             list.add("Bulk: "+getBulkDisplay(design.bulk));
  198.         }
  199.         list.add(EnumChatFormatting.BLUE+StatCollector.translateToLocal("attribute.armour.protection") + " " + rating + attatch);
  200.         */
  201.     }
  202.  
  203.     private void addModifier(List list, float ratio, String name)
  204.     {
  205.         if(getProtectionRatio() != ratio)
  206.         {
  207.             if(getProtectionRatio() > ratio)
  208.             {
  209.                 float percent = (ratio / getProtectionRatio())-1F;
  210.                 list.add(EnumChatFormatting.RED+
  211.                         StatCollector.translateToLocalFormatted("attribute.modifier.take."+ 1,
  212.                                 decimal_format.format(-percent * 100),
  213.                                         StatCollector.translateToLocal("attribute.armour."+name)));
  214.             }else
  215.             {
  216.                 float percent = (ratio / getProtectionRatio())-1F;
  217.                 list.add(EnumChatFormatting.DARK_GREEN+
  218.                         StatCollector.translateToLocalFormatted("attribute.modifier.plus."+ 1,
  219.                                 decimal_format.format(percent * 100),
  220.                                         StatCollector.translateToLocal("attribute.armour."+name)));
  221.             }
  222.         }
  223.     }
  224.     /**
  225.      * Gets the bulk for display(Make sure to count the bulk for the piece)
  226.      */
  227.     public static int getBulkDisplay(float bulk)
  228.     {
  229.         return (int) (bulk*100);
  230.     }
  231.     public ArmourMaterialMF getMaterial()
  232.     {
  233.         return this.material;
  234.     }
  235.    
  236.     @Override
  237.     public int getMaxDamage(ItemStack stack)
  238.     {
  239.         if(isUnbreakable())
  240.         {
  241.             setUnbreakable(stack);
  242.         }
  243.         return ToolHelper.setDuraOnQuality(stack, super.getMaxDamage());
  244.     }
  245.  
  246.     protected boolean isUnbreakable()
  247.     {
  248.         return false;
  249.     }
  250.  
  251.     @Override
  252.     public float scalePiece(ItemStack item)
  253.     {
  254.         return scalePiece();
  255.     }
  256.    
  257.     @Override
  258.     public int getItemEnchantability()
  259.     {
  260.         return material.enchantment;
  261.     }
  262.  
  263.     @Override
  264.     public float getPieceWeight(ItemStack item, int slot)
  265.     {
  266.         return armourWeight * ArmourCalculator.sizes[slot];
  267.     }
  268.    
  269.     public static void setUnbreakable(ItemStack tool)
  270.     {
  271.         if(!tool.hasTagCompound())
  272.         {
  273.             tool.setTagCompound(new NBTTagCompound());
  274.         }
  275.         tool.getTagCompound().setBoolean("Unbreakable", true);
  276.     }
  277.    
  278.     private static final float[] AC = new float[]{40F, 60F};
  279.  
  280.     @Override
  281.     public String getSuitWeigthType(ItemStack item)
  282.     {
  283.         if(design == ArmourDesign.CLOTH)return null;
  284.        
  285.         return armourWeight >= ArmourCalculator.ACArray[1] ? "heavy" : armourWeight >= ArmourCalculator.ACArray[0] ? "medium" : "light";
  286.     }
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement