Advertisement
lol123406

EtherealArmor.java

Apr 28th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.49 KB | None | 0 0
  1. package net.Ethereal.armor;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import net.Ethereal.main.ClientProxy;
  6. import net.Ethereal.main.EtherealStrings;
  7. import net.minecraft.client.model.ModelBiped;
  8. import net.minecraft.client.renderer.texture.IIconRegister;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.Entity;
  11. import net.minecraft.entity.EntityLivingBase;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.item.EnumAction;
  14. import net.minecraft.item.ItemArmor;
  15. import net.minecraft.item.ItemStack;
  16.  
  17. public class EtherealArmor extends ItemArmor{
  18.  
  19.     public EtherealArmor(ArmorMaterial material, int render_idx, int type) {
  20.         super(material, render_idx, type);
  21.        
  22.         this.setMaxStackSize(1);
  23.         this.setCreativeTab(CreativeTabs.tabMisc);
  24.        
  25.     }
  26.    
  27.     @Override
  28.     public String getUnlocalizedName(){
  29.         return String.format("item.%s%s", EtherealStrings.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
  30.     }
  31.    
  32.     @Override
  33.     public String getUnlocalizedName(ItemStack itemstack){
  34.         return String.format("item.%s%s", EtherealStrings.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
  35.     }
  36.    
  37.     protected String getUnwrappedUnlocalizedName(String unlocalizedName){      
  38.         return unlocalizedName.substring(unlocalizedName.indexOf('.') + 1);
  39.     }
  40.    
  41.     @Override
  42.     @SideOnly(Side.CLIENT)
  43.     public void registerIcons(IIconRegister iconRegister){
  44.         this.itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf('.') + 1));
  45.     }
  46.    
  47.     @Override
  48.     @SideOnly(Side.CLIENT)
  49.     public ModelBiped getArmorModel (EntityLivingBase entityLiving, ItemStack itemstack, int armorSlot){
  50.        
  51.         ModelBiped armorModel = ClientProxy.armorModels.get(this);
  52.        
  53.         if(armorModel != null){
  54.             armorModel.bipedHead.showModel = armorSlot == 0;
  55.             armorModel.bipedHeadwear.showModel = false;
  56.             armorModel.bipedBody.showModel = armorSlot == 1 || armorSlot == 2;
  57.             armorModel.bipedRightArm.showModel = armorSlot == 1;
  58.             armorModel.bipedLeftArm.showModel = armorSlot == 1;
  59.             armorModel.bipedRightLeg.showModel = armorSlot == 2 || armorSlot == 3;
  60.             armorModel.bipedLeftLeg.showModel = armorSlot == 2 || armorSlot == 3;
  61.            
  62.             armorModel.isSneak = entityLiving.isSneaking();
  63.             armorModel.isRiding = entityLiving.isRiding();
  64.             armorModel.isChild = entityLiving.isChild();
  65.            
  66.             armorModel.heldItemRight = 0;
  67.             armorModel.aimedBow = false;
  68.            
  69.             EntityPlayer player = (EntityPlayer)entityLiving;
  70.            
  71.             ItemStack held_item = player.getEquipmentInSlot(0);
  72.            
  73.             if (held_item != null){
  74.                 armorModel.heldItemRight = 1;
  75.                
  76.                 if (player.getItemInUseCount() > 0){
  77.                    
  78.                     EnumAction enumaction = held_item.getItemUseAction();
  79.                    
  80.                     if (enumaction == EnumAction.bow){
  81.                         armorModel.aimedBow = true;
  82.                     }else if (enumaction == EnumAction.block){
  83.                         armorModel.heldItemRight = 3;
  84.                     }
  85.                    
  86.                    
  87.                 }
  88.                
  89.             }
  90.            
  91.            
  92.         }
  93.        
  94.        
  95.         return armorModel;
  96.     }
  97.    
  98.    
  99.     @Override
  100.     public String getArmorTexture(ItemStack stack, Entity entity, int slot, String layer){
  101.        
  102.         String name = this.getUnwrappedUnlocalizedName(super.getUnlocalizedName());
  103.         name = name.substring(0, name.indexOf('_'));
  104.        
  105.         return String.format("%s:textures/models/armor/%s_layer_%d.png", EtherealStrings.modid, name, slot == 2 ? 2 : 1);
  106.     }
  107.    
  108.    
  109.    
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement