Advertisement
Arctic_Wolfy

ItemArmorPaper.class #4

Mar 3rd, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.99 KB | None | 0 0
  1. package com.arctic.paperArmor.items;
  2.  
  3. import com.arctic.paperArmor.handlers.Inscriptions;
  4. import com.arctic.paperArmor.init.ModItems;
  5. import net.minecraft.entity.EntityLivingBase;
  6. import net.minecraft.entity.item.EntityItem;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.init.Items;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemArmor;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.util.ChatComponentText;
  15. import net.minecraft.util.DamageSource;
  16. import net.minecraft.util.IChatComponent;
  17. import net.minecraft.world.World;
  18. import net.minecraftforge.common.ISpecialArmor;
  19.  
  20. import java.util.List;
  21.  
  22. public class ItemArmorPaper extends ItemArmorPA implements ISpecialArmor{
  23.     public ItemArmorPaper(int armorType) {
  24.         super("paper", paper, armorType);
  25.     }
  26.  
  27.     private final int water = 20;
  28.     private final int fire = 10;
  29.  
  30.     private final int[] armorCounts = {5,8,7,4};
  31.     private final int[] armorSlots = {3,2,1,0};
  32.  
  33.     @Override
  34.     public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) {
  35.         return new ArmorProperties(0, ((ItemArmor)armor.getItem()).damageReduceAmount / 25D , armor.getMaxDamage() + 1 - armor.getItemDamage());
  36.     }
  37.  
  38.     @Override
  39.     public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
  40.         return ((ItemArmor)armor.getItem()).damageReduceAmount;
  41.     }
  42.  
  43.     @Override
  44.     public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {
  45.         if (!source.isFireDamage())
  46.             stack.damageItem(damage,entity);
  47.     }
  48.  
  49.     protected enum Damage{
  50.         water(Items.string,"water"),
  51.         fire(null,"fire"),
  52.         generic(Items.paper,null);
  53.  
  54.         Item drop;
  55.         String msg;
  56.         Damage(Item drop, String msg){
  57.             this.drop = drop;
  58.             this.msg = msg;
  59.         }
  60.     }
  61.  
  62.     @Override
  63.     public void onArmorTick(World world, EntityPlayer player, ItemStack stack) {
  64.         super.onArmorTick(world, player, stack);
  65.         if (!world.isRemote) {
  66.             if (stack.hasTagCompound()) {
  67.                 if (player.isWet()){
  68.                     if (stack.getTagCompound().hasKey("WetTick")){
  69.                         wetTick(player, stack);
  70.                     } else {
  71.                         stack.getTagCompound().setInteger("WetTick", water);
  72.                     }
  73.                 } else if (player.isBurning()){
  74.                     if (stack.getTagCompound().hasKey("FireTick")){
  75.                         fireTick(player, stack);
  76.                     } else {
  77.                         stack.getTagCompound().setInteger("FireTick", fire);
  78.                     }
  79.                 }
  80.                 for (Inscriptions inscription : Inscriptions.values()) {
  81.                     if (Inscriptions.hasInscription(stack,inscription)){
  82.                         Inscriptions.applyInscription(player,stack,inscription);
  83.                     }
  84.                 }
  85.             } else {
  86.                 stack.setTagCompound(new NBTTagCompound());
  87.             }
  88.         }
  89.     }
  90.  
  91.     private void breakPaper(EntityPlayer player, ItemStack stack){
  92.         int amount = armorCounts[armorType];
  93.  
  94.         ItemStack stackDrop = new ItemStack(Items.paper,amount);
  95.         EntityItem item = new EntityItem(player.worldObj,player.posX,player.posY,player.posZ);
  96.         item.setEntityItemStack(stackDrop);
  97.         player.worldObj.spawnEntityInWorld(item);
  98.     }
  99.  
  100.     private void wetTick(EntityPlayer player, ItemStack stack){
  101.         int wetTick = stack.getTagCompound().getInteger("WetTick");
  102.         if (wetTick == 0) {
  103.             damagePiece(player,stack,Damage.water);
  104.             wetTick = water;
  105.         } else wetTick--;
  106.         stack.getTagCompound().setInteger("WetTick", wetTick);
  107.     }
  108.  
  109.     private void fireTick(EntityPlayer player, ItemStack stack){
  110.         int fireTick = stack.getTagCompound().getInteger("FireTick");
  111.         if (fireTick == 0) {
  112.             damagePiece(player,stack,Damage.fire);
  113.             fireTick = fire;
  114.         } else fireTick--;
  115.         stack.getTagCompound().setInteger("FireTick", fireTick);
  116.     }
  117.  
  118.     private void damagePiece(EntityPlayer player, ItemStack stack, Damage damage){
  119.         stack.damageItem(1,player);
  120.         if (stack.stackSize == 0){
  121.             int amount = 0;
  122.             if (player.getCurrentArmor(armorSlots[armorType])!=null) {
  123.                 //player.addChatComponentMessage(player.getCurrentArmor(armorSlots[armorType]).func_151000_E().appendText(" "+armorType));
  124.                 if (stack.getItem() == player.getCurrentArmor(armorSlots[armorType]).getItem()) {
  125.                     player.inventory.armorInventory[armorSlots[armorType]] = null;
  126.                     amount = armorCounts[armorType];
  127.                 }
  128.                 if (damage != null) {
  129.                     if (damage.msg != null) playBreakMSG(player, stack, damage.msg);
  130.                     if (damage.drop != null && amount > 0) {
  131.                         ItemStack stackDrop = new ItemStack(damage.drop, amount);
  132.                         EntityItem item = new EntityItem(player.worldObj, player.posX, player.posY, player.posZ);
  133.                         item.setEntityItemStack(stackDrop);
  134.                         player.worldObj.spawnEntityInWorld(item);
  135.                     }
  136.                 }
  137.             }
  138.         }
  139.     }
  140.  
  141.     private void playBreakMSG(EntityPlayer player, ItemStack stack, String src){
  142.         IChatComponent msg = stack.func_151000_E();
  143.         msg.appendText(" It seams paper and "+src+" do not mix.");
  144.         player.addChatComponentMessage(msg);
  145.     }
  146.  
  147.     public int getDurabilityRemaining(ItemStack stack){
  148.         return stack.getMaxDamage()-stack.getItemDamage();
  149.     }
  150.  
  151.     @Override
  152.     public boolean requiresMultipleRenderPasses() {
  153.         return super.requiresMultipleRenderPasses();
  154.     }
  155.  
  156.     @Override
  157.     public int getRenderPasses(int metadata) {
  158.         return super.getRenderPasses(metadata);
  159.     }
  160.  
  161.     @Override
  162.     public boolean hasEffect(ItemStack stack, int pass) {
  163.         return super.hasEffect(stack, pass);
  164.     }
  165.  
  166.     @Override
  167.     public boolean hasEffect(ItemStack stack) {
  168.         for (Inscriptions inscription : Inscriptions.values())
  169.             if (Inscriptions.hasInscription(stack,inscription))
  170.                 return true;
  171.         return false;
  172.     }
  173.  
  174.     @Override
  175.     public void addInformation(ItemStack stack, EntityPlayer player, List info, boolean bool) {
  176.         for (Inscriptions inscription : Inscriptions.values()) {
  177.             if (Inscriptions.hasInscription(stack, inscription)) {
  178.                 info.add("Inscribed with " + inscription.name().toLowerCase());
  179.             }
  180.         }
  181.     }
  182.  
  183.     @Override
  184.     public boolean getIsRepairable(ItemStack armor, ItemStack repair) {
  185.         return repair.getItem() == ModItems.lacedPaperTile;
  186.     }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement