20 févr. 2017, 15:40
public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn)
{
   if(worldIn.getBlockState(pos.up(7)).getBlock().isWood(worldIn, pos.up(7))
   {
        if(playerIn instanceof EntityPlayer && !worldIn.isRemote)
        {
             ((EntityPlayer)playerIn).sendChatMessage(new ChatComponantText("Cet arbre est trop grand pour pouvoir être coupé"));
        }
        return super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn);
   }
   for (int i = 0 ; i < 7; i++)
   {
       BlockPos testPos = pos.up(i);
       if(worldIn.getBlockState(testPos).getBlock().isWood(worldIn, testPos))
       {
           stack.damageItem(1, playerIn);

           if (!worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops"))
           {
               float f = 0.7F;

               double d0 = (double)(worldIn.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
               double d1 = (double)(worldIn.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
               double d2 = (double)(worldIn.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;

               EntityItem entityItem = new EntityItem(worldIn, (double)testPos.getX() + d0, (double)testPos.getY() + d1, (double)testPos.getZ() + d2, new ItemStack(Item.getItemFromBlock(blockIn), 1));
               entityItem.setDefaultPickupDelay();
               worldIn.spawnEntityInWorld(entityItem);
           }
           worldIn.setBlockToAir(testPos);
       }
       else
       {
           return super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn);
       }
   }
   return super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn);
}