Advertisement
HalestormXV

Untitled

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