Advertisement
HalestormXV

Untitled

Feb 8th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.44 KB | None | 0 0
  1. package com.halestormxv.item;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import com.halestormxv.lib.RefStrings;
  8.  
  9. import cpw.mods.fml.relauncher.Side;
  10. import cpw.mods.fml.relauncher.SideOnly;
  11. import net.minecraft.block.Block;
  12. import net.minecraft.creativetab.CreativeTabs;
  13. import net.minecraft.enchantment.Enchantment;
  14. import net.minecraft.enchantment.EnchantmentHelper;
  15. import net.minecraft.entity.Entity;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.item.EntityItem;
  18. import net.minecraft.entity.passive.EntityChicken;
  19. import net.minecraft.entity.player.EntityPlayer;
  20. import net.minecraft.item.EnumRarity;
  21. import net.minecraft.item.ItemShears;
  22. import net.minecraft.item.ItemStack;
  23. import net.minecraft.stats.StatList;
  24. import net.minecraft.util.EnumChatFormatting;
  25. import net.minecraftforge.common.IShearable;
  26.  
  27. public class celShears extends ItemShears
  28. {
  29.     public celShears()
  30.     {
  31.         this.setMaxStackSize(1);
  32.         this.setTextureName(RefStrings.MODID + ":celestial_shears");
  33.         this.setMaxDamage(600);
  34.     }
  35.  
  36.     public boolean isDamageable()
  37.     {
  38.         return false;
  39.     }
  40.  
  41.     @Override
  42.     @SideOnly(Side.CLIENT)
  43.     public EnumRarity getRarity(ItemStack par1ItemStack){
  44.         return EnumRarity.uncommon;
  45.     }
  46.  
  47.     @Override
  48.     public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
  49.     {
  50.         par3List.add("");
  51.         par3List.add(EnumChatFormatting.LIGHT_PURPLE + "Mystical shears imbued with Aries's power.");
  52.         par3List.add(EnumChatFormatting.LIGHT_PURPLE + "Aries is a timid and easy spirit to gain trust from.");
  53.         par3List.add(EnumChatFormatting.LIGHT_PURPLE + "However, because of this she is often taken");
  54.         par3List.add(EnumChatFormatting.LIGHT_PURPLE + "advantage of. You have proven to be a good");
  55.         par3List.add(EnumChatFormatting.LIGHT_PURPLE + "and kind Matster.");
  56.         par3List.add("");
  57.         par3List.add(EnumChatFormatting.UNDERLINE + "Shears sheep in a radius.");
  58.     }
  59.  
  60.     @Override
  61.     public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity)
  62.     {
  63.         if (entity.worldObj.isRemote)
  64.         {
  65.             return false;
  66.         }
  67.         List<IShearable> shearList = entity.worldObj.getEntitiesWithinAABBExcludingEntity(player, entity.boundingBox.expand(8.0D, 8.0D, 8.0D));
  68.         for (int i = 0; i < shearList.size(); i++)
  69.         {
  70.             Entity target = (Entity) shearList.get(i);
  71.             if (target instanceof IShearable)
  72.             {
  73.                 IShearable shearable = (IShearable)target;
  74.                 if (((IShearable) target).isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ) )
  75.                 {              
  76.                     ArrayList<ItemStack> drops = ((IShearable) target).onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ,
  77.                             EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
  78.  
  79.                     Random rand = new Random();
  80.                     for(ItemStack stack : drops)
  81.                     {
  82.                         EntityItem ent = entity.entityDropItem(stack, 1.0F);
  83.                         ent.motionY += rand.nextFloat() * 0.05F;
  84.                         ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
  85.                         ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
  86.                     }
  87.                 }else{
  88.  
  89.                 }
  90.                 return true;
  91.             }
  92.         }
  93.         return false;
  94.     }
  95.  
  96.     @Override
  97.     public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player)
  98.     {
  99.         if (player.worldObj.isRemote)
  100.         {
  101.             return false;
  102.         }
  103.         Block block = player.worldObj.getBlock(x, y, z);
  104.         if (block instanceof IShearable)
  105.         {
  106.             IShearable target = (IShearable)block;
  107.             if (target.isShearable(itemstack, player.worldObj, x, y, z))
  108.             {
  109.                 ArrayList<ItemStack> drops = target.onSheared(itemstack, player.worldObj, x, y, z,
  110.                         EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
  111.                 Random rand = new Random();
  112.  
  113.                 for(ItemStack stack : drops)
  114.                 {
  115.                     float f = 0.7F;
  116.                     double d  = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  117.                     double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  118.                     double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  119.                     EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack);
  120.                     entityitem.delayBeforeCanPickup = 10;
  121.                     player.worldObj.spawnEntityInWorld(entityitem);
  122.                 }
  123.                 player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1);
  124.             }
  125.         }
  126.         return false;
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement