001 package net.minecraft.src; 002 003 import java.util.ArrayList; 004 005 import net.minecraftforge.common.IShearable; 006 007 public class ItemShears extends Item 008 { 009 public ItemShears(int par1) 010 { 011 super(par1); 012 this.setMaxStackSize(1); 013 this.setMaxDamage(238); 014 this.setTabToDisplayOn(CreativeTabs.tabTools); 015 } 016 017 public boolean func_77660_a(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving) 018 { 019 if (par3 != Block.leaves.blockID && par3 != Block.web.blockID && par3 != Block.tallGrass.blockID && par3 != Block.vine.blockID && par3 != Block.tripWire.blockID && !(Block.blocksList[par3] instanceof IShearable)) 020 { 021 return super.func_77660_a(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLiving); 022 } 023 else 024 { 025 return true; 026 } 027 } 028 029 /** 030 * Returns if the item (tool) can harvest results from the block type. 031 */ 032 public boolean canHarvestBlock(Block par1Block) 033 { 034 return par1Block.blockID == Block.web.blockID; 035 } 036 037 /** 038 * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if 039 * sword 040 */ 041 public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) 042 { 043 return par2Block.blockID != Block.web.blockID && par2Block.blockID != Block.leaves.blockID ? (par2Block.blockID == Block.cloth.blockID ? 5.0F : super.getStrVsBlock(par1ItemStack, par2Block)) : 15.0F; 044 } 045 046 @Override 047 public boolean itemInteractionForEntity(ItemStack itemstack, EntityLiving entity) 048 { 049 if (entity.worldObj.isRemote) 050 { 051 return false; 052 } 053 if (entity instanceof IShearable) 054 { 055 IShearable target = (IShearable)entity; 056 if (target.isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ)) 057 { 058 ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ, 059 EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack)); 060 for(ItemStack stack : drops) 061 { 062 EntityItem ent = entity.entityDropItem(stack, 1.0F); 063 ent.motionY += entity.rand.nextFloat() * 0.05F; 064 ent.motionX += (entity.rand.nextFloat() - entity.rand.nextFloat()) * 0.1F; 065 ent.motionZ += (entity.rand.nextFloat() - entity.rand.nextFloat()) * 0.1F; 066 } 067 itemstack.damageItem(1, entity); 068 } 069 return true; 070 } 071 return false; 072 } 073 074 @Override 075 public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player) 076 { 077 if (player.worldObj.isRemote) 078 { 079 return false; 080 } 081 int id = player.worldObj.getBlockId(x, y, z); 082 if (Block.blocksList[id] instanceof IShearable) 083 { 084 IShearable target = (IShearable)Block.blocksList[id]; 085 if (target.isShearable(itemstack, player.worldObj, x, y, z)) 086 { 087 ArrayList<ItemStack> drops = target.onSheared(itemstack, player.worldObj, x, y, z, 088 EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack)); 089 for(ItemStack stack : drops) 090 { 091 float f = 0.7F; 092 double d = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; 093 double d1 = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; 094 double d2 = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; 095 EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack); 096 entityitem.delayBeforeCanPickup = 10; 097 player.worldObj.spawnEntityInWorld(entityitem); 098 } 099 itemstack.damageItem(1, player); 100 player.addStat(StatList.mineBlockStatArray[id], 1); 101 } 102 } 103 return false; 104 } 105 }