Advertisement
HalestormXV

Untitled

Feb 8th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 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 net.minecraft.block.Block;
  10. import net.minecraft.creativetab.CreativeTabs;
  11. import net.minecraft.enchantment.Enchantment;
  12. import net.minecraft.enchantment.EnchantmentHelper;
  13. import net.minecraft.entity.EntityLivingBase;
  14. import net.minecraft.entity.item.EntityItem;
  15. import net.minecraft.entity.passive.EntityChicken;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.item.ItemShears;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.stats.StatList;
  20. import net.minecraft.util.AxisAlignedBB;
  21. import net.minecraft.world.World;
  22. import net.minecraftforge.common.IShearable;
  23.  
  24. public class celShears extends ItemShears
  25. {
  26.     public celShears()
  27.     {
  28.         this.setMaxStackSize(1);
  29.         this.setTextureName(RefStrings.MODID + ":celestial_shears");
  30.         this.setMaxDamage(600);
  31.     }
  32.  
  33.     public boolean isDamageable()
  34.     {
  35.         return false;
  36.     }
  37.  
  38.     @Override
  39.     public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity)
  40.     {
  41.         if (entity.worldObj.isRemote)
  42.         {
  43.             return false;
  44.         }
  45.         List shearList = entity.worldObj.getEntitiesWithinAABBExcludingEntity(player, entity.boundingBox.expand(6.0F, 6.0F, 6.0F));
  46.         for (int i = 0; i < shearList.size(); i++)
  47.         {
  48.             IShearable target = (IShearable)shearList.get(i);
  49.             if (entity instanceof IShearable)
  50.             {          
  51.                 if (target.isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ) )
  52.                 {              
  53.                     ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ,
  54.                             EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
  55.  
  56.                     Random rand = new Random();
  57.                     for(ItemStack stack : drops)
  58.                     {
  59.                         EntityItem ent = entity.entityDropItem(stack, 1.0F);
  60.                         ent.motionY += rand.nextFloat() * 0.05F;
  61.                         ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
  62.                         ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
  63.                     }
  64.                 }
  65.                 return true;
  66.             }
  67.         }
  68.         return false;
  69.     }
  70.  
  71.     @Override
  72.     public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player)
  73.     {
  74.         if (player.worldObj.isRemote)
  75.         {
  76.             return false;
  77.         }
  78.         Block block = player.worldObj.getBlock(x, y, z);
  79.         if (block instanceof IShearable)
  80.         {
  81.             IShearable target = (IShearable)block;
  82.             if (target.isShearable(itemstack, player.worldObj, x, y, z))
  83.             {
  84.                 ArrayList<ItemStack> drops = target.onSheared(itemstack, player.worldObj, x, y, z,
  85.                         EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
  86.                 Random rand = new Random();
  87.  
  88.                 for(ItemStack stack : drops)
  89.                 {
  90.                     float f = 0.7F;
  91.                     double d  = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  92.                     double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  93.                     double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  94.                     EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack);
  95.                     entityitem.delayBeforeCanPickup = 10;
  96.                     player.worldObj.spawnEntityInWorld(entityitem);
  97.                 }
  98.                 player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1);
  99.             }
  100.         }
  101.         return false;
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement