Advertisement
Guest User

Untitled

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