Files
MinecraftForge/patches/common/net/minecraft/src/ItemShears.java.patch
T

92 lines
4.1 KiB
Diff

--- ../src_base/common/net/minecraft/src/ItemShears.java
+++ ../src_work/common/net/minecraft/src/ItemShears.java
@@ -1,4 +1,8 @@
package net.minecraft.src;
+
+import java.util.ArrayList;
+
+import net.minecraftforge.common.IShearable;
public class ItemShears extends Item
{
@@ -12,13 +16,12 @@
public boolean func_77660_a(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving)
{
- if (par3 != Block.leaves.blockID && par3 != Block.web.blockID && par3 != Block.tallGrass.blockID && par3 != Block.vine.blockID && par3 != Block.tripWire.blockID)
+ 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))
{
return super.func_77660_a(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLiving);
}
else
{
- par1ItemStack.damageItem(1, par7EntityLiving);
return true;
}
}
@@ -39,4 +42,64 @@
{
return par2Block.blockID != Block.web.blockID && par2Block.blockID != Block.leaves.blockID ? (par2Block.blockID == Block.cloth.blockID ? 5.0F : super.getStrVsBlock(par1ItemStack, par2Block)) : 15.0F;
}
+
+ @Override
+ public boolean itemInteractionForEntity(ItemStack itemstack, EntityLiving entity)
+ {
+ if (entity.worldObj.isRemote)
+ {
+ return false;
+ }
+ if (entity instanceof IShearable)
+ {
+ IShearable target = (IShearable)entity;
+ if (target.isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ))
+ {
+ ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ,
+ EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
+ for(ItemStack stack : drops)
+ {
+ EntityItem ent = entity.entityDropItem(stack, 1.0F);
+ ent.motionY += entity.rand.nextFloat() * 0.05F;
+ ent.motionX += (entity.rand.nextFloat() - entity.rand.nextFloat()) * 0.1F;
+ ent.motionZ += (entity.rand.nextFloat() - entity.rand.nextFloat()) * 0.1F;
+ }
+ itemstack.damageItem(1, entity);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player)
+ {
+ if (player.worldObj.isRemote)
+ {
+ return false;
+ }
+ int id = player.worldObj.getBlockId(x, y, z);
+ if (Block.blocksList[id] instanceof IShearable)
+ {
+ IShearable target = (IShearable)Block.blocksList[id];
+ if (target.isShearable(itemstack, player.worldObj, x, y, z))
+ {
+ ArrayList<ItemStack> drops = target.onSheared(itemstack, player.worldObj, x, y, z,
+ EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
+ for(ItemStack stack : drops)
+ {
+ float f = 0.7F;
+ double d = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
+ double d1 = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
+ double d2 = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
+ EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack);
+ entityitem.delayBeforeCanPickup = 10;
+ player.worldObj.spawnEntityInWorld(entityitem);
+ }
+ itemstack.damageItem(1, player);
+ player.addStat(StatList.mineBlockStatArray[id], 1);
+ }
+ }
+ return false;
+ }
}