Advertisement
Superloup10

Code foireux

Apr 18th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. package wolf_addons.common.item.kit.redstone;
  2.  
  3. import net.minecraft.client.renderer.texture.IIconRegister;
  4. import net.minecraft.entity.EntityLivingBase;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.item.ItemSword;
  8. import net.minecraft.nbt.NBTTagCompound;
  9. import net.minecraft.util.ChatComponentTranslation;
  10. import net.minecraft.util.IIcon;
  11. import net.minecraft.world.World;
  12. import wolf_addons.common.item.WolfItemList;
  13. import cpw.mods.fml.relauncher.Side;
  14. import cpw.mods.fml.relauncher.SideOnly;
  15.  
  16. public class RedstoneSword extends ItemSword
  17. {
  18.     @SideOnly(Side.CLIENT)
  19.     private IIcon[] textures = new IIcon[2];
  20.    
  21.     public RedstoneSword(ToolMaterial material)
  22.     {
  23.         super(material);
  24.     }
  25.    
  26.     @Override
  27.     public boolean getIsRepairable(ItemStack input, ItemStack repair)
  28.     {
  29.         if(repair.getItem().equals(WolfItemList.redstoneIngot))
  30.         {
  31.             return true;
  32.         }
  33.         return false;
  34.     }
  35.    
  36.     @Override
  37.     public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
  38.     {
  39.         ItemStack helmet = player.getEquipmentInSlot(4);
  40.         ItemStack chestplate = player.getEquipmentInSlot(3);
  41.         ItemStack leggings = player.getEquipmentInSlot(2);
  42.         ItemStack boots = player.getEquipmentInSlot(1);
  43.        
  44.         if(helmet != null && helmet.getItem() == WolfItemList.redstoneHelmet && chestplate != null &&  chestplate.getItem() == WolfItemList.redstoneChestplate && leggings != null && leggings.getItem() == WolfItemList.redstoneLeggings && boots != null && boots.getItem() == WolfItemList.redstoneBoots)
  45.         {
  46.             if(player.isSneaking())
  47.             {
  48.                 if(!itemStack.hasTagCompound())
  49.                 {
  50.                     itemStack.setTagCompound(new NBTTagCompound());
  51.                 }
  52.                 if(!helmet.hasTagCompound())
  53.                 {
  54.                     helmet.setTagCompound(new NBTTagCompound());
  55.                 }
  56.                 byte mode = itemStack.getTagCompound().getByte("Mode");
  57.                 mode++;
  58.                 if(mode == 2)
  59.                 {
  60.                     mode = 0;
  61.                 }
  62.                 itemStack.getTagCompound().setByte("Mode", mode);
  63.                 helmet.getTagCompound().setByte("Mode", mode);
  64.                 chestplate.getTagCompound().setByte("Mode", mode);
  65.                 leggings.getTagCompound().setByte("Mode", mode);
  66.                 boots.getTagCompound().setByte("Mode", mode);
  67.  
  68.                 if(world.isRemote)
  69.                 {
  70.                     player.addChatMessage(new ChatComponentTranslation("sword.mode.message." + mode));
  71.                 }
  72.             }
  73.             else
  74.             {
  75.                 super.onItemRightClick(itemStack, world, player);
  76.             }
  77.         }
  78.         else
  79.         {
  80.             super.onItemRightClick(itemStack, world, player);
  81.         }
  82.         return itemStack;
  83.     }
  84.    
  85.     @Override
  86.     public boolean hitEntity(ItemStack stack, EntityLivingBase attackedLiving, EntityLivingBase attackerLiving)
  87.     {
  88.         if(!stack.hasTagCompound())
  89.         {
  90.             stack.setTagCompound(new NBTTagCompound());
  91.         }
  92.        
  93.         if(stack.getTagCompound().getByte("Mode") == 0)
  94.         {
  95.             return super.hitEntity(stack, attackedLiving, attackerLiving);
  96.         }
  97.         else
  98.         {
  99.             attackedLiving.setFire(4);
  100.         }
  101.         return super.hitEntity(stack, attackedLiving, attackerLiving);
  102.     }
  103.    
  104.     @SideOnly(Side.CLIENT)
  105.     public IIcon getIconFromDamage(int par1)
  106.     {
  107.         return this.itemIcon;
  108.     }
  109.    
  110.     @SideOnly(Side.CLIENT)
  111.     @Override
  112.     public IIcon getIconIndex(ItemStack itemStack)
  113.     {
  114.         if(!itemStack.hasTagCompound())
  115.         {
  116.             itemStack.setTagCompound(new NBTTagCompound());
  117.         }
  118.        
  119.         if(itemStack.getTagCompound().getByte("Mode") == 0)
  120.         {
  121.             return textures[0];
  122.         }
  123.         else
  124.         {
  125.             return textures[1];
  126.         }
  127.     }
  128.    
  129.     @Override
  130.     public void registerIcons(IIconRegister register)
  131.     {
  132.         textures[0] = register.registerIcon("wolf_addons:redstone_sword_off");
  133.         textures[1] = register.registerIcon("wolf_addons:redstone_sword_on");
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement